Merge remote-tracking branch 'goog/master' into mergescriptpackage

main
Ken Wakasa 2012-11-16 19:49:39 +09:00
commit 0b82582270
11 changed files with 175 additions and 171 deletions

View File

@ -633,7 +633,7 @@ public final class KeyboardState {
@Override @Override
public String toString() { public String toString() {
return "[keyboard=" + (mIsAlphabetMode ? mAlphabetShiftState.toString() return "[keyboard=" + (mIsAlphabetMode ? mAlphabetShiftState.toString()
: (mIsSymbolShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS")) : (mIsSymbolShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS"))
+ " shift=" + mShiftKeyState + " shift=" + mShiftKeyState
+ " symbol=" + mSymbolKeyState + " symbol=" + mSymbolKeyState
+ " switch=" + switchStateToString(mSwitchState) + "]"; + " switch=" + switchStateToString(mSwitchState) + "]";

View File

@ -101,7 +101,7 @@ public final class BinaryDictionary extends Dictionary {
} }
private native long openNative(String sourceDir, long dictOffset, long dictSize, private native long openNative(String sourceDir, long dictOffset, long dictSize,
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions); int maxWordLength, int maxWords, int maxPredictions);
private native void closeNative(long dict); private native void closeNative(long dict);
private native int getFrequencyNative(long dict, int[] word); private native int getFrequencyNative(long dict, int[] word);
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2); private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
@ -116,8 +116,8 @@ public final class BinaryDictionary extends Dictionary {
// TODO: Move native dict into session // TODO: Move native dict into session
private final void loadDictionary(final String path, final long startOffset, private final void loadDictionary(final String path, final long startOffset,
final long length) { final long length) {
mNativeDict = openNative(path, startOffset, length, FULL_WORD_SCORE_MULTIPLIER, mNativeDict = openNative(path, startOffset, length, MAX_WORD_LENGTH, MAX_WORDS,
MAX_WORD_LENGTH, MAX_WORDS, MAX_PREDICTIONS); MAX_PREDICTIONS);
} }
@Override @Override

View File

@ -26,11 +26,6 @@ import java.util.ArrayList;
* strokes. * strokes.
*/ */
public abstract class Dictionary { public abstract class Dictionary {
/**
* The weight to give to a word if it's length is the same as the number of typed characters.
*/
protected static final int FULL_WORD_SCORE_MULTIPLIER = 2;
public static final int NOT_A_PROBABILITY = -1; public static final int NOT_A_PROBABILITY = -1;
public static final String TYPE_USER_TYPED = "user_typed"; public static final String TYPE_USER_TYPED = "user_typed";

View File

@ -31,6 +31,10 @@ import java.util.LinkedList;
* be searched for suggestions and valid words. * be searched for suggestions and valid words.
*/ */
public class ExpandableDictionary extends Dictionary { public class ExpandableDictionary extends Dictionary {
/**
* The weight to give to a word if it's length is the same as the number of typed characters.
*/
private static final int FULL_WORD_SCORE_MULTIPLIER = 2;
// Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8. // Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8.
protected static final int BIGRAM_MAX_FREQUENCY = 255; protected static final int BIGRAM_MAX_FREQUENCY = 255;

View File

@ -43,9 +43,8 @@ class ProximityInfo;
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd); static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, jstring sourceDir,
jstring sourceDir, jlong dictOffset, jlong dictSize, jint fullWordMultiplier, jlong dictOffset, jlong dictSize, jint maxWordLength, jint maxWords, jint maxPredictions) {
jint maxWordLength, jint maxWords, jint maxPredictions) {
PROF_OPEN; PROF_OPEN;
PROF_START(66); PROF_START(66);
const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir); const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir);
@ -119,8 +118,8 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
releaseDictBuf(dictBuf, 0, 0); releaseDictBuf(dictBuf, 0, 0);
#endif // USE_MMAP_FOR_DICTIONARY #endif // USE_MMAP_FOR_DICTIONARY
} else { } else {
dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust, dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust, maxWordLength,
fullWordMultiplier, maxWordLength, maxWords, maxPredictions); maxWords, maxPredictions);
} }
PROF_END(66); PROF_END(66);
PROF_CLOSE; PROF_CLOSE;
@ -272,7 +271,7 @@ static void releaseDictBuf(const void *dictBuf, const size_t length, const int f
} }
static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = {
{"openNative", "(Ljava/lang/String;JJIIII)J", {"openNative", "(Ljava/lang/String;JJIII)J",
reinterpret_cast<void *>(latinime_BinaryDictionary_open)}, reinterpret_cast<void *>(latinime_BinaryDictionary_open)},
{"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)}, {"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)},
{"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I", {"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I",

View File

@ -29,13 +29,13 @@
namespace latinime { namespace latinime {
// TODO: Change the type of all keyCodes to uint32_t // TODO: Change the type of all keyCodes to uint32_t
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength,
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions) int maxWords, int maxPredictions)
: mDict(static_cast<unsigned char *>(dict)), : mDict(static_cast<unsigned char *>(dict)),
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)), mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, fullWordMultiplier, maxWordLength, mUnigramDictionary(new UnigramDictionary(mOffsetDict, maxWordLength, maxWords,
maxWords, BinaryFormat::getFlags(mDict))), BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)), mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)),
mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) { mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) {
if (DEBUG_DICT) { if (DEBUG_DICT) {

View File

@ -41,8 +41,8 @@ class Dictionary {
const static int KIND_SHORTCUT = 7; // A shortcut const static int KIND_SHORTCUT = 7; // A shortcut
const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input) const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int fullWordMultiplier, Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength,
int maxWordLength, int maxWords, int maxPredictions); int maxWords, int maxPredictions);
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates, int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize, int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,

View File

@ -95,11 +95,11 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
pushTouchPointStartIndex = mInputIndice[mInputIndice.size() - 2]; pushTouchPointStartIndex = mInputIndice[mInputIndice.size() - 2];
popInputData(); popInputData();
popInputData(); popInputData();
lastSavedInputSize = mInputXs.size(); lastSavedInputSize = mSampledInputXs.size();
} else { } else {
// Clear all data. // Clear all data.
mInputXs.clear(); mSampledInputXs.clear();
mInputYs.clear(); mSampledInputYs.clear();
mTimes.clear(); mTimes.clear();
mInputIndice.clear(); mInputIndice.clear();
mLengthCache.clear(); mLengthCache.clear();
@ -114,7 +114,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
AKLOGI("Init ProximityInfoState: reused points = %d, last input size = %d", AKLOGI("Init ProximityInfoState: reused points = %d, last input size = %d",
pushTouchPointStartIndex, lastSavedInputSize); pushTouchPointStartIndex, lastSavedInputSize);
} }
mInputSize = 0; mSampledInputSize = 0;
if (xCoordinates && yCoordinates) { if (xCoordinates && yCoordinates) {
const bool proximityOnly = !isGeometric && (xCoordinates[0] < 0 || yCoordinates[0] < 0); const bool proximityOnly = !isGeometric && (xCoordinates[0] < 0 || yCoordinates[0] < 0);
@ -175,77 +175,33 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
} }
} }
} }
mInputSize = mInputXs.size(); mSampledInputSize = mSampledInputXs.size();
} }
if (mInputSize > 0 && isGeometric) { if (mSampledInputSize > 0 && isGeometric) {
// Relative speed calculation. refreshRelativeSpeed(inputSize, xCoordinates, yCoordinates, times, lastSavedInputSize);
const int sumDuration = mTimes.back() - mTimes.front();
const int sumLength = mLengthCache.back() - mLengthCache.front();
const float averageSpeed = static_cast<float>(sumLength) / static_cast<float>(sumDuration);
mRelativeSpeeds.resize(mInputSize);
for (int i = lastSavedInputSize; i < mInputSize; ++i) {
const int index = mInputIndice[i];
int length = 0;
int duration = 0;
// Calculate velocity by using distances and durations of
// NUM_POINTS_FOR_SPEED_CALCULATION points for both forward and backward.
static const int NUM_POINTS_FOR_SPEED_CALCULATION = 2;
for (int j = index; j < min(inputSize - 1, index + NUM_POINTS_FOR_SPEED_CALCULATION);
++j) {
if (i < mInputSize - 1 && j >= mInputIndice[i + 1]) {
break;
}
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
xCoordinates[j + 1], yCoordinates[j + 1]);
duration += times[j + 1] - times[j];
}
for (int j = index - 1; j >= max(0, index - NUM_POINTS_FOR_SPEED_CALCULATION); --j) {
if (i > 0 && j < mInputIndice[i - 1]) {
break;
}
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
xCoordinates[j + 1], yCoordinates[j + 1]);
duration += times[j + 1] - times[j];
}
if (duration == 0 || sumDuration == 0) {
// Cannot calculate speed; thus, it gives an average value (1.0);
mRelativeSpeeds[i] = 1.0f;
} else {
const float speed = static_cast<float>(length) / static_cast<float>(duration);
mRelativeSpeeds[i] = speed / averageSpeed;
}
}
// Direction calculation.
mDirections.resize(mInputSize - 1);
for (int i = max(0, lastSavedInputSize - 1); i < mInputSize - 1; ++i) {
mDirections[i] = getDirection(i, i + 1);
}
} }
if (DEBUG_GEO_FULL) { if (DEBUG_GEO_FULL) {
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mSampledInputSize; ++i) {
AKLOGI("Sampled(%d): x = %d, y = %d, time = %d", i, mInputXs[i], mInputYs[i], AKLOGI("Sampled(%d): x = %d, y = %d, time = %d", i, mSampledInputXs[i],
mTimes[i]); mSampledInputYs[i], mTimes[i]);
} }
} }
if (mInputSize > 0) { if (mSampledInputSize > 0) {
const int keyCount = mProximityInfo->getKeyCount(); const int keyCount = mProximityInfo->getKeyCount();
mNearKeysVector.resize(mInputSize); mNearKeysVector.resize(mSampledInputSize);
mSearchKeysVector.resize(mInputSize); mSearchKeysVector.resize(mSampledInputSize);
mDistanceCache.resize(mInputSize * keyCount); mDistanceCache.resize(mSampledInputSize * keyCount);
for (int i = lastSavedInputSize; i < mInputSize; ++i) { for (int i = lastSavedInputSize; i < mSampledInputSize; ++i) {
mNearKeysVector[i].reset(); mNearKeysVector[i].reset();
mSearchKeysVector[i].reset(); mSearchKeysVector[i].reset();
static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f; static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f;
for (int k = 0; k < keyCount; ++k) { for (int k = 0; k < keyCount; ++k) {
const int index = i * keyCount + k; const int index = i * keyCount + k;
const int x = mInputXs[i]; const int x = mSampledInputXs[i];
const int y = mInputYs[i]; const int y = mSampledInputYs[i];
const float normalizedSquaredDistance = const float normalizedSquaredDistance =
mProximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y); mProximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y);
mDistanceCache[index] = normalizedSquaredDistance; mDistanceCache[index] = normalizedSquaredDistance;
@ -262,11 +218,11 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
const int readForwordLength = static_cast<int>( const int readForwordLength = static_cast<int>(
hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight()) hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight())
* READ_FORWORD_LENGTH_SCALE); * READ_FORWORD_LENGTH_SCALE);
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mSampledInputSize; ++i) {
if (i >= lastSavedInputSize) { if (i >= lastSavedInputSize) {
mSearchKeysVector[i].reset(); mSearchKeysVector[i].reset();
} }
for (int j = max(i, lastSavedInputSize); j < mInputSize; ++j) { for (int j = max(i, lastSavedInputSize); j < mSampledInputSize; ++j) {
if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) { if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) {
break; break;
} }
@ -286,30 +242,31 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
originalY << ";"; originalY << ";";
} }
} }
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mSampledInputSize; ++i) {
sampledX << mInputXs[i]; sampledX << mSampledInputXs[i];
sampledY << mInputYs[i]; sampledY << mSampledInputYs[i];
if (i != mInputSize - 1) { if (i != mSampledInputSize - 1) {
sampledX << ";"; sampledX << ";";
sampledY << ";"; sampledY << ";";
} }
} }
AKLOGI("\n%s, %s,\n%s, %s,\n", originalX.str().c_str(), originalY.str().c_str(), AKLOGI("original points:\n%s, %s,\nsampled points:\n%s, %s,\n",
sampledX.str().c_str(), sampledY.str().c_str()); originalX.str().c_str(), originalY.str().c_str(), sampledX.str().c_str(),
sampledY.str().c_str());
} }
// end // end
/////////////////////// ///////////////////////
memset(mNormalizedSquaredDistances, NOT_A_DISTANCE, sizeof(mNormalizedSquaredDistances)); memset(mNormalizedSquaredDistances, NOT_A_DISTANCE, sizeof(mNormalizedSquaredDistances));
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord)); memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
mTouchPositionCorrectionEnabled = mInputSize > 0 && mHasTouchPositionCorrectionData mTouchPositionCorrectionEnabled = mSampledInputSize > 0 && mHasTouchPositionCorrectionData
&& xCoordinates && yCoordinates; && xCoordinates && yCoordinates;
if (!isGeometric && pointerId == 0) { if (!isGeometric && pointerId == 0) {
for (int i = 0; i < inputSize; ++i) { for (int i = 0; i < inputSize; ++i) {
mPrimaryInputWord[i] = getPrimaryCodePointAt(i); mPrimaryInputWord[i] = getPrimaryCodePointAt(i);
} }
for (int i = 0; i < mInputSize && mTouchPositionCorrectionEnabled; ++i) { for (int i = 0; i < mSampledInputSize && mTouchPositionCorrectionEnabled; ++i) {
const int *proximityCodePoints = getProximityCodePointsAt(i); const int *proximityCodePoints = getProximityCodePointsAt(i);
const int primaryKey = proximityCodePoints[0]; const int primaryKey = proximityCodePoints[0];
const int x = xCoordinates[i]; const int x = xCoordinates[i];
@ -342,16 +299,64 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
} }
if (DEBUG_GEO_FULL) { if (DEBUG_GEO_FULL) {
AKLOGI("ProximityState init finished: %d points out of %d", mInputSize, inputSize); AKLOGI("ProximityState init finished: %d points out of %d", mSampledInputSize, inputSize);
}
}
void ProximityInfoState::refreshRelativeSpeed(const int inputSize, const int *const xCoordinates,
const int *const yCoordinates, const int *const times, const int lastSavedInputSize) {
// Relative speed calculation.
const int sumDuration = mTimes.back() - mTimes.front();
const int sumLength = mLengthCache.back() - mLengthCache.front();
const float averageSpeed = static_cast<float>(sumLength) / static_cast<float>(sumDuration);
mRelativeSpeeds.resize(mSampledInputSize);
for (int i = lastSavedInputSize; i < mSampledInputSize; ++i) {
const int index = mInputIndice[i];
int length = 0;
int duration = 0;
// Calculate velocity by using distances and durations of
// NUM_POINTS_FOR_SPEED_CALCULATION points for both forward and backward.
static const int NUM_POINTS_FOR_SPEED_CALCULATION = 2;
for (int j = index; j < min(inputSize - 1, index + NUM_POINTS_FOR_SPEED_CALCULATION);
++j) {
if (i < mSampledInputSize - 1 && j >= mInputIndice[i + 1]) {
break;
}
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
xCoordinates[j + 1], yCoordinates[j + 1]);
duration += times[j + 1] - times[j];
}
for (int j = index - 1; j >= max(0, index - NUM_POINTS_FOR_SPEED_CALCULATION); --j) {
if (i > 0 && j < mInputIndice[i - 1]) {
break;
}
length += getDistanceInt(xCoordinates[j], yCoordinates[j],
xCoordinates[j + 1], yCoordinates[j + 1]);
duration += times[j + 1] - times[j];
}
if (duration == 0 || sumDuration == 0) {
// Cannot calculate speed; thus, it gives an average value (1.0);
mRelativeSpeeds[i] = 1.0f;
} else {
const float speed = static_cast<float>(length) / static_cast<float>(duration);
mRelativeSpeeds[i] = speed / averageSpeed;
}
}
// Direction calculation.
mDirections.resize(mSampledInputSize - 1);
for (int i = max(0, lastSavedInputSize - 1); i < mSampledInputSize - 1; ++i) {
mDirections[i] = getDirection(i, i + 1);
} }
} }
bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize, bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize,
const int *const xCoordinates, const int *const yCoordinates, const int *const times) { const int *const xCoordinates, const int *const yCoordinates, const int *const times) {
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mSampledInputSize; ++i) {
const int index = mInputIndice[i]; const int index = mInputIndice[i];
if (index > inputSize || xCoordinates[index] != mInputXs[i] || if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] ||
yCoordinates[index] != mInputYs[i] || times[index] != mTimes[i]) { yCoordinates[index] != mSampledInputYs[i] || times[index] != mTimes[i]) {
return false; return false;
} }
} }
@ -412,7 +417,7 @@ float ProximityInfoState::getPointScore(
static const float CORNER_SUM_ANGLE_THRESHOLD = M_PI_F / 4.0f; static const float CORNER_SUM_ANGLE_THRESHOLD = M_PI_F / 4.0f;
static const float CORNER_SCORE = 1.0f; static const float CORNER_SCORE = 1.0f;
const size_t size = mInputXs.size(); const size_t size = mSampledInputXs.size();
// If there is only one point, add this point. Besides, if the previous point's distance map // If there is only one point, add this point. Besides, if the previous point's distance map
// is empty, we re-compute nearby keys distances from the current point. // is empty, we re-compute nearby keys distances from the current point.
// Note that the current point is the first point in the incremental input that needs to // Note that the current point is the first point in the incremental input that needs to
@ -422,8 +427,8 @@ float ProximityInfoState::getPointScore(
} }
const int baseSampleRate = mProximityInfo->getMostCommonKeyWidth(); const int baseSampleRate = mProximityInfo->getMostCommonKeyWidth();
const int distPrev = getDistanceInt(mInputXs.back(), mInputYs.back(), const int distPrev = getDistanceInt(mSampledInputXs.back(), mSampledInputYs.back(),
mInputXs[size - 2], mInputYs[size - 2]) * DISTANCE_BASE_SCALE; mSampledInputXs[size - 2], mSampledInputYs[size - 2]) * DISTANCE_BASE_SCALE;
float score = 0.0f; float score = 0.0f;
// Location // Location
@ -435,9 +440,9 @@ float ProximityInfoState::getPointScore(
score += LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE; score += LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
} }
// Angle // Angle
const float angle1 = getAngle(x, y, mInputXs.back(), mInputYs.back()); const float angle1 = getAngle(x, y, mSampledInputXs.back(), mSampledInputYs.back());
const float angle2 = getAngle(mInputXs.back(), mInputYs.back(), const float angle2 = getAngle(mSampledInputXs.back(), mSampledInputYs.back(),
mInputXs[size - 2], mInputYs[size - 2]); mSampledInputXs[size - 2], mSampledInputYs[size - 2]);
const float angleDiff = getAngleDiff(angle1, angle2); const float angleDiff = getAngleDiff(angle1, angle2);
// Save corner // Save corner
@ -457,7 +462,7 @@ bool ProximityInfoState::pushTouchPoint(const int inputIndex, const int nodeCode
const NearKeysDistanceMap *const prevPrevNearKeysDistances) { const NearKeysDistanceMap *const prevPrevNearKeysDistances) {
static const int LAST_POINT_SKIP_DISTANCE_SCALE = 4; static const int LAST_POINT_SKIP_DISTANCE_SCALE = 4;
size_t size = mInputXs.size(); size_t size = mSampledInputXs.size();
bool popped = false; bool popped = false;
if (nodeCodePoint < 0 && sample) { if (nodeCodePoint < 0 && sample) {
const float nearest = updateNearKeysDistances(x, y, currentNearKeysDistances); const float nearest = updateNearKeysDistances(x, y, currentNearKeysDistances);
@ -466,20 +471,20 @@ bool ProximityInfoState::pushTouchPoint(const int inputIndex, const int nodeCode
if (score < 0) { if (score < 0) {
// Pop previous point because it would be useless. // Pop previous point because it would be useless.
popInputData(); popInputData();
size = mInputXs.size(); size = mSampledInputXs.size();
popped = true; popped = true;
} else { } else {
popped = false; popped = false;
} }
// Check if the last point should be skipped. // Check if the last point should be skipped.
if (isLastPoint && size > 0) { if (isLastPoint && size > 0) {
if (getDistanceInt(x, y, mInputXs.back(), mInputYs.back()) if (getDistanceInt(x, y, mSampledInputXs.back(), mSampledInputYs.back())
* LAST_POINT_SKIP_DISTANCE_SCALE < mProximityInfo->getMostCommonKeyWidth()) { * LAST_POINT_SKIP_DISTANCE_SCALE < mProximityInfo->getMostCommonKeyWidth()) {
// This point is not used because it's too close to the previous point. // This point is not used because it's too close to the previous point.
if (DEBUG_GEO_FULL) { if (DEBUG_GEO_FULL) {
AKLOGI("p0: size = %zd, x = %d, y = %d, lx = %d, ly = %d, dist = %d, " AKLOGI("p0: size = %zd, x = %d, y = %d, lx = %d, ly = %d, dist = %d, "
"width = %d", size, x, y, mInputXs.back(), mInputYs.back(), "width = %d", size, x, y, mSampledInputXs.back(), mSampledInputYs.back(),
getDistanceInt(x, y, mInputXs.back(), mInputYs.back()), getDistanceInt(x, y, mSampledInputXs.back(), mSampledInputYs.back()),
mProximityInfo->getMostCommonKeyWidth() mProximityInfo->getMostCommonKeyWidth()
/ LAST_POINT_SKIP_DISTANCE_SCALE); / LAST_POINT_SKIP_DISTANCE_SCALE);
} }
@ -499,12 +504,13 @@ bool ProximityInfoState::pushTouchPoint(const int inputIndex, const int nodeCode
// Pushing point information. // Pushing point information.
if (size > 0) { if (size > 0) {
mLengthCache.push_back( mLengthCache.push_back(
mLengthCache.back() + getDistanceInt(x, y, mInputXs.back(), mInputYs.back())); mLengthCache.back() + getDistanceInt(
x, y, mSampledInputXs.back(), mSampledInputYs.back()));
} else { } else {
mLengthCache.push_back(0); mLengthCache.push_back(0);
} }
mInputXs.push_back(x); mSampledInputXs.push_back(x);
mInputYs.push_back(y); mSampledInputYs.push_back(y);
mTimes.push_back(time); mTimes.push_back(time);
mInputIndice.push_back(inputIndex); mInputIndice.push_back(inputIndex);
if (DEBUG_GEO_FULL) { if (DEBUG_GEO_FULL) {
@ -522,7 +528,7 @@ float ProximityInfoState::calculateNormalizedSquaredDistance(
if (!mProximityInfo->hasSweetSpotData(keyIndex)) { if (!mProximityInfo->hasSweetSpotData(keyIndex)) {
return NOT_A_DISTANCE_FLOAT; return NOT_A_DISTANCE_FLOAT;
} }
if (NOT_A_COORDINATE == mInputXs[inputIndex]) { if (NOT_A_COORDINATE == mSampledInputXs[inputIndex]) {
return NOT_A_DISTANCE_FLOAT; return NOT_A_DISTANCE_FLOAT;
} }
const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter( const float squaredDistance = calculateSquaredDistanceFromSweetSpotCenter(
@ -532,7 +538,7 @@ float ProximityInfoState::calculateNormalizedSquaredDistance(
} }
int ProximityInfoState::getDuration(const int index) const { int ProximityInfoState::getDuration(const int index) const {
if (index >= 0 && index < mInputSize - 1) { if (index >= 0 && index < mSampledInputSize - 1) {
return mTimes[index + 1] - mTimes[index]; return mTimes[index + 1] - mTimes[index];
} }
return 0; return 0;
@ -631,15 +637,15 @@ float ProximityInfoState::calculateSquaredDistanceFromSweetSpotCenter(
const int keyIndex, const int inputIndex) const { const int keyIndex, const int inputIndex) const {
const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex); const float sweetSpotCenterX = mProximityInfo->getSweetSpotCenterXAt(keyIndex);
const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex); const float sweetSpotCenterY = mProximityInfo->getSweetSpotCenterYAt(keyIndex);
const float inputX = static_cast<float>(mInputXs[inputIndex]); const float inputX = static_cast<float>(mSampledInputXs[inputIndex]);
const float inputY = static_cast<float>(mInputYs[inputIndex]); const float inputY = static_cast<float>(mSampledInputYs[inputIndex]);
return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY); return square(inputX - sweetSpotCenterX) + square(inputY - sweetSpotCenterY);
} }
// Puts possible characters into filter and returns new filter size. // Puts possible characters into filter and returns new filter size.
int32_t ProximityInfoState::getAllPossibleChars( int32_t ProximityInfoState::getAllPossibleChars(
const size_t index, int32_t *const filter, const int32_t filterSize) const { const size_t index, int32_t *const filter, const int32_t filterSize) const {
if (index >= mInputXs.size()) { if (index >= mSampledInputXs.size()) {
return filterSize; return filterSize;
} }
int newFilterSize = filterSize; int newFilterSize = filterSize;
@ -665,34 +671,34 @@ int32_t ProximityInfoState::getAllPossibleChars(
bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const { bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const {
ASSERT(keyId >= 0); ASSERT(keyId >= 0);
ASSERT(index >= 0 && index < mInputSize); ASSERT(index >= 0 && index < mSampledInputSize);
return mSearchKeysVector[index].test(keyId); return mSearchKeysVector[index].test(keyId);
} }
void ProximityInfoState::popInputData() { void ProximityInfoState::popInputData() {
mInputXs.pop_back(); mSampledInputXs.pop_back();
mInputYs.pop_back(); mSampledInputYs.pop_back();
mTimes.pop_back(); mTimes.pop_back();
mLengthCache.pop_back(); mLengthCache.pop_back();
mInputIndice.pop_back(); mInputIndice.pop_back();
} }
float ProximityInfoState::getDirection(const int index0, const int index1) const { float ProximityInfoState::getDirection(const int index0, const int index1) const {
if (index0 < 0 || index0 > mInputSize - 1) { if (index0 < 0 || index0 > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
if (index1 < 0 || index1 > mInputSize - 1) { if (index1 < 0 || index1 > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
const int x1 = mInputXs[index0]; const int x1 = mSampledInputXs[index0];
const int y1 = mInputYs[index0]; const int y1 = mSampledInputYs[index0];
const int x2 = mInputXs[index1]; const int x2 = mSampledInputXs[index1];
const int y2 = mInputYs[index1]; const int y2 = mSampledInputYs[index1];
return getAngle(x1, y1, x2, y2); return getAngle(x1, y1, x2, y2);
} }
float ProximityInfoState::getPointAngle(const int index) const { float ProximityInfoState::getPointAngle(const int index) const {
if (index <= 0 || index >= mInputSize - 1) { if (index <= 0 || index >= mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
const float previousDirection = getDirection(index - 1, index); const float previousDirection = getDirection(index - 1, index);
@ -703,13 +709,13 @@ float ProximityInfoState::getPointAngle(const int index) const {
float ProximityInfoState::getPointsAngle( float ProximityInfoState::getPointsAngle(
const int index0, const int index1, const int index2) const { const int index0, const int index1, const int index2) const {
if (index0 < 0 || index0 > mInputSize - 1) { if (index0 < 0 || index0 > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
if (index1 < 0 || index1 > mInputSize - 1) { if (index1 < 0 || index1 > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
if (index2 < 0 || index2 > mInputSize - 1) { if (index2 < 0 || index2 > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
const float previousDirection = getDirection(index0, index1); const float previousDirection = getDirection(index0, index1);
@ -719,16 +725,16 @@ float ProximityInfoState::getPointsAngle(
float ProximityInfoState::getLineToKeyDistance( float ProximityInfoState::getLineToKeyDistance(
const int from, const int to, const int keyId, const bool extend) const { const int from, const int to, const int keyId, const bool extend) const {
if (from < 0 || from > mInputSize - 1) { if (from < 0 || from > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
if (to < 0 || to > mInputSize - 1) { if (to < 0 || to > mSampledInputSize - 1) {
return 0.0f; return 0.0f;
} }
const int x0 = mInputXs[from]; const int x0 = mSampledInputXs[from];
const int y0 = mInputYs[from]; const int y0 = mSampledInputYs[from];
const int x1 = mInputXs[to]; const int x1 = mSampledInputXs[to];
const int y1 = mInputYs[to]; const int y1 = mSampledInputYs[to];
const int keyX = mProximityInfo->getKeyCenterXOfKeyIdG(keyId); const int keyX = mProximityInfo->getKeyCenterXOfKeyIdG(keyId);
const int keyY = mProximityInfo->getKeyCenterYOfKeyIdG(keyId); const int keyY = mProximityInfo->getKeyCenterYOfKeyIdG(keyId);
@ -761,10 +767,10 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
static const float CENTER_VALUE_OF_NORMALIZED_DISTRIBUTION = 0.0f; static const float CENTER_VALUE_OF_NORMALIZED_DISTRIBUTION = 0.0f;
const int keyCount = mProximityInfo->getKeyCount(); const int keyCount = mProximityInfo->getKeyCount();
mCharProbabilities.resize(mInputSize); mCharProbabilities.resize(mSampledInputSize);
// Calculates probabilities of using a point as a correlated point with the character // Calculates probabilities of using a point as a correlated point with the character
// for each point. // for each point.
for (int i = start; i < mInputSize; ++i) { for (int i = start; i < mSampledInputSize; ++i) {
mCharProbabilities[i].clear(); mCharProbabilities[i].clear();
// First, calculates skip probability. Starts form MIN_SKIP_PROBABILITY. // First, calculates skip probability. Starts form MIN_SKIP_PROBABILITY.
// Note that all values that are multiplied to this probability should be in [0.0, 1.0]; // Note that all values that are multiplied to this probability should be in [0.0, 1.0];
@ -788,7 +794,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
+ NEAREST_DISTANCE_BIAS); + NEAREST_DISTANCE_BIAS);
// Promote the first point // Promote the first point
skipProbability *= SKIP_FIRST_POINT_PROBABILITY; skipProbability *= SKIP_FIRST_POINT_PROBABILITY;
} else if (i == mInputSize - 1) { } else if (i == mSampledInputSize - 1) {
skipProbability *= min(1.0f, nearestKeyDistance * NEAREST_DISTANCE_WEIGHT_FOR_LAST skipProbability *= min(1.0f, nearestKeyDistance * NEAREST_DISTANCE_WEIGHT_FOR_LAST
+ NEAREST_DISTANCE_BIAS_FOR_LAST); + NEAREST_DISTANCE_BIAS_FOR_LAST);
// Promote the last point // Promote the last point
@ -860,7 +866,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
for (int j = 0; j < keyCount; ++j) { for (int j = 0; j < keyCount; ++j) {
if (mNearKeysVector[i].test(j)) { if (mNearKeysVector[i].test(j)) {
float distance = sqrtf(getPointToKeyByIdLength(i, j)); float distance = sqrtf(getPointToKeyByIdLength(i, j));
if (i == 0 && i != mInputSize - 1) { if (i == 0 && i != mSampledInputSize - 1) {
// For the first point, weighted average of distances from first point and the // For the first point, weighted average of distances from first point and the
// next point to the key is used as a point to key distance. // next point to the key is used as a point to key distance.
const float nextDistance = sqrtf(getPointToKeyByIdLength(i + 1, j)); const float nextDistance = sqrtf(getPointToKeyByIdLength(i + 1, j));
@ -872,7 +878,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
distance = (distance + nextDistance * NEXT_DISTANCE_WEIGHT) distance = (distance + nextDistance * NEXT_DISTANCE_WEIGHT)
/ (1.0f + NEXT_DISTANCE_WEIGHT); / (1.0f + NEXT_DISTANCE_WEIGHT);
} }
} else if (i != 0 && i == mInputSize - 1) { } else if (i != 0 && i == mSampledInputSize - 1) {
// For the first point, weighted average of distances from last point and // For the first point, weighted average of distances from last point and
// the previous point to the key is used as a point to key distance. // the previous point to the key is used as a point to key distance.
const float previousDistance = sqrtf(getPointToKeyByIdLength(i - 1, j)); const float previousDistance = sqrtf(getPointToKeyByIdLength(i - 1, j));
@ -895,7 +901,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
for (int j = 0; j < keyCount; ++j) { for (int j = 0; j < keyCount; ++j) {
if (mNearKeysVector[i].test(j)) { if (mNearKeysVector[i].test(j)) {
float distance = sqrtf(getPointToKeyByIdLength(i, j)); float distance = sqrtf(getPointToKeyByIdLength(i, j));
if (i == 0 && i != mInputSize - 1) { if (i == 0 && i != mSampledInputSize - 1) {
// For the first point, weighted average of distances from the first point and // For the first point, weighted average of distances from the first point and
// the next point to the key is used as a point to key distance. // the next point to the key is used as a point to key distance.
const float prevDistance = sqrtf(getPointToKeyByIdLength(i + 1, j)); const float prevDistance = sqrtf(getPointToKeyByIdLength(i + 1, j));
@ -903,7 +909,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
distance = (distance + prevDistance * NEXT_DISTANCE_WEIGHT) distance = (distance + prevDistance * NEXT_DISTANCE_WEIGHT)
/ (1.0f + NEXT_DISTANCE_WEIGHT); / (1.0f + NEXT_DISTANCE_WEIGHT);
} }
} else if (i != 0 && i == mInputSize - 1) { } else if (i != 0 && i == mSampledInputSize - 1) {
// For the first point, weighted average of distances from last point and // For the first point, weighted average of distances from last point and
// the previous point to the key is used as a point to key distance. // the previous point to the key is used as a point to key distance.
const float prevDistance = sqrtf(getPointToKeyByIdLength(i - 1, j)); const float prevDistance = sqrtf(getPointToKeyByIdLength(i - 1, j));
@ -922,11 +928,10 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
if (DEBUG_POINTS_PROBABILITY) { if (DEBUG_POINTS_PROBABILITY) {
for (int i = 0; i < mInputSize; ++i) { for (int i = 0; i < mSampledInputSize; ++i) {
std::stringstream sstream; std::stringstream sstream;
sstream << i << ", "; sstream << i << ", ";
sstream << "("<< mInputXs[i] << ", "; sstream << "(" << mSampledInputXs[i] << ", " << mSampledInputYs[i] << "), ";
sstream << ", "<< mInputYs[i] << "), ";
sstream << "Speed: "<< getRelativeSpeed(i) << ", "; sstream << "Speed: "<< getRelativeSpeed(i) << ", ";
sstream << "Angle: "<< getPointAngle(i) << ", \n"; sstream << "Angle: "<< getPointAngle(i) << ", \n";
@ -952,8 +957,8 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
// Decrease key probabilities of points which don't have the highest probability of that key // Decrease key probabilities of points which don't have the highest probability of that key
// among nearby points. Probabilities of the first point and the last point are not suppressed. // among nearby points. Probabilities of the first point and the last point are not suppressed.
for (int i = max(start, 1); i < mInputSize; ++i) { for (int i = max(start, 1); i < mSampledInputSize; ++i) {
for (int j = i + 1; j < mInputSize; ++j) { for (int j = i + 1; j < mSampledInputSize; ++j) {
if (!suppressCharProbabilities(i, j)) { if (!suppressCharProbabilities(i, j)) {
break; break;
} }
@ -966,7 +971,7 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
} }
// Converting from raw probabilities to log probabilities to calculate spatial distance. // Converting from raw probabilities to log probabilities to calculate spatial distance.
for (int i = start; i < mInputSize; ++i) { for (int i = start; i < mSampledInputSize; ++i) {
for (int j = 0; j < keyCount; ++j) { for (int j = 0; j < keyCount; ++j) {
hash_map_compat<int, float>::iterator it = mCharProbabilities[i].find(j); hash_map_compat<int, float>::iterator it = mCharProbabilities[i].find(j);
if (it == mCharProbabilities[i].end()){ if (it == mCharProbabilities[i].end()){
@ -986,8 +991,8 @@ void ProximityInfoState::updateAlignPointProbabilities(const int start) {
// Decreases char probabilities of index0 by checking probabilities of a near point (index1) and // Decreases char probabilities of index0 by checking probabilities of a near point (index1) and
// increases char probabilities of index1 by checking probabilities of index0. // increases char probabilities of index1 by checking probabilities of index0.
bool ProximityInfoState::suppressCharProbabilities(const int index0, const int index1) { bool ProximityInfoState::suppressCharProbabilities(const int index0, const int index1) {
ASSERT(0 <= index0 && index0 < mInputSize); ASSERT(0 <= index0 && index0 < mSampledInputSize);
ASSERT(0 <= index1 && index1 < mInputSize); ASSERT(0 <= index1 && index1 < mSampledInputSize);
static const float SUPPRESSION_LENGTH_WEIGHT = 1.5f; static const float SUPPRESSION_LENGTH_WEIGHT = 1.5f;
static const float MIN_SUPPRESSION_RATE = 0.1f; static const float MIN_SUPPRESSION_RATE = 0.1f;
@ -1030,7 +1035,7 @@ float ProximityInfoState::getHighestProbabilitySequence(int *const codePointBuf)
int index = 0; int index = 0;
float sumLogProbability = 0.0f; float sumLogProbability = 0.0f;
// TODO: Current implementation is greedy algorithm. DP would be efficient for many cases. // TODO: Current implementation is greedy algorithm. DP would be efficient for many cases.
for (int i = 0; i < mInputSize && index < MAX_WORD_LENGTH_INTERNAL - 1; ++i) { for (int i = 0; i < mSampledInputSize && index < MAX_WORD_LENGTH_INTERNAL - 1; ++i) {
float minLogProbability = static_cast<float>(MAX_POINT_TO_KEY_LENGTH); float minLogProbability = static_cast<float>(MAX_POINT_TO_KEY_LENGTH);
int character = NOT_AN_INDEX; int character = NOT_AN_INDEX;
for (hash_map_compat<int, float>::const_iterator it = mCharProbabilities[i].begin(); for (hash_map_compat<int, float>::const_iterator it = mCharProbabilities[i].begin();
@ -1054,7 +1059,7 @@ float ProximityInfoState::getHighestProbabilitySequence(int *const codePointBuf)
// Returns a probability of mapping index to keyIndex. // Returns a probability of mapping index to keyIndex.
float ProximityInfoState::getProbability(const int index, const int keyIndex) const { float ProximityInfoState::getProbability(const int index, const int keyIndex) const {
ASSERT(0 <= index && index < mInputSize); ASSERT(0 <= index && index < mSampledInputSize);
hash_map_compat<int, float>::const_iterator it = mCharProbabilities[index].find(keyIndex); hash_map_compat<int, float>::const_iterator it = mCharProbabilities[index].find(keyIndex);
if (it != mCharProbabilities[index].end()) { if (it != mCharProbabilities[index].end()) {
return it->second; return it->second;

View File

@ -54,10 +54,10 @@ class ProximityInfoState {
: mProximityInfo(0), mMaxPointToKeyLength(0), : mProximityInfo(0), mMaxPointToKeyLength(0),
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(), mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(),
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0), mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
mIsContinuationPossible(false), mInputXs(), mInputYs(), mTimes(), mInputIndice(), mIsContinuationPossible(false), mSampledInputXs(), mSampledInputYs(), mTimes(),
mDistanceCache(), mLengthCache(), mRelativeSpeeds(), mDirections(), mInputIndice(), mDistanceCache(), mLengthCache(), mRelativeSpeeds(), mDirections(),
mCharProbabilities(), mNearKeysVector(), mSearchKeysVector(), mCharProbabilities(), mNearKeysVector(), mSearchKeysVector(),
mTouchPositionCorrectionEnabled(false), mInputSize(0) { mTouchPositionCorrectionEnabled(false), mSampledInputSize(0) {
memset(mInputCodes, 0, sizeof(mInputCodes)); memset(mInputCodes, 0, sizeof(mInputCodes));
memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances)); memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord)); memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
@ -82,14 +82,15 @@ class ProximityInfoState {
} }
inline bool existsAdjacentProximityChars(const int index) const { inline bool existsAdjacentProximityChars(const int index) const {
if (index < 0 || index >= mInputSize) return false; if (index < 0 || index >= mSampledInputSize) return false;
const int currentCodePoint = getPrimaryCodePointAt(index); const int currentCodePoint = getPrimaryCodePointAt(index);
const int leftIndex = index - 1; const int leftIndex = index - 1;
if (leftIndex >= 0 && existsCodePointInProximityAt(leftIndex, currentCodePoint)) { if (leftIndex >= 0 && existsCodePointInProximityAt(leftIndex, currentCodePoint)) {
return true; return true;
} }
const int rightIndex = index + 1; const int rightIndex = index + 1;
if (rightIndex < mInputSize && existsCodePointInProximityAt(rightIndex, currentCodePoint)) { if (rightIndex < mSampledInputSize
&& existsCodePointInProximityAt(rightIndex, currentCodePoint)) {
return true; return true;
} }
return false; return false;
@ -110,7 +111,7 @@ class ProximityInfoState {
} }
inline bool sameAsTyped(const int *word, int length) const { inline bool sameAsTyped(const int *word, int length) const {
if (length != mInputSize) { if (length != mSampledInputSize) {
return false; return false;
} }
const int *inputCodes = mInputCodes; const int *inputCodes = mInputCodes;
@ -127,19 +128,19 @@ class ProximityInfoState {
int getDuration(const int index) const; int getDuration(const int index) const;
bool isUsed() const { bool isUsed() const {
return mInputSize > 0; return mSampledInputSize > 0;
} }
uint32_t size() const { uint32_t size() const {
return mInputSize; return mSampledInputSize;
} }
int getInputX(const int index) const { int getInputX(const int index) const {
return mInputXs[index]; return mSampledInputXs[index];
} }
int getInputY(const int index) const { int getInputY(const int index) const {
return mInputYs[index]; return mSampledInputYs[index];
} }
int getLengthCache(const int index) const { int getLengthCache(const int index) const {
@ -205,7 +206,7 @@ class ProximityInfoState {
inline float square(const float x) const { return x * x; } inline float square(const float x) const { return x * x; }
bool hasInputCoordinates() const { bool hasInputCoordinates() const {
return mInputXs.size() > 0 && mInputYs.size() > 0; return mSampledInputXs.size() > 0 && mSampledInputYs.size() > 0;
} }
inline const int *getProximityCodePointsAt(const int index) const { inline const int *getProximityCodePointsAt(const int index) const {
@ -227,6 +228,8 @@ class ProximityInfoState {
void popInputData(); void popInputData();
void updateAlignPointProbabilities(const int start); void updateAlignPointProbabilities(const int start);
bool suppressCharProbabilities(const int index1, const int index2); bool suppressCharProbabilities(const int index1, const int index2);
void refreshRelativeSpeed(const int inputSize, const int *const xCoordinates,
const int *const yCoordinates, const int *const times, const int lastSavedInputSize);
// const // const
const ProximityInfo *mProximityInfo; const ProximityInfo *mProximityInfo;
@ -241,8 +244,8 @@ class ProximityInfoState {
int mGridWidth; int mGridWidth;
bool mIsContinuationPossible; bool mIsContinuationPossible;
std::vector<int> mInputXs; std::vector<int> mSampledInputXs;
std::vector<int> mInputYs; std::vector<int> mSampledInputYs;
std::vector<int> mTimes; std::vector<int> mTimes;
std::vector<int> mInputIndice; std::vector<int> mInputIndice;
std::vector<float> mDistanceCache; std::vector<float> mDistanceCache;
@ -263,7 +266,7 @@ class ProximityInfoState {
bool mTouchPositionCorrectionEnabled; bool mTouchPositionCorrectionEnabled;
int mInputCodes[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL]; int mInputCodes[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL];
int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL]; int mNormalizedSquaredDistances[MAX_PROXIMITY_CHARS_SIZE_INTERNAL * MAX_WORD_LENGTH_INTERNAL];
int mInputSize; int mSampledInputSize;
int mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL]; int mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
}; };
} // namespace latinime } // namespace latinime

View File

@ -41,10 +41,9 @@ const UnigramDictionary::digraph_t UnigramDictionary::FRENCH_LIGATURES_DIGRAPHS[
{ 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE { 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE
// TODO: check the header // TODO: check the header
UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int fullWordMultiplier, UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int maxWordLength,
int maxWordLength, int maxWords, const unsigned int flags) int maxWords, const unsigned int flags)
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords), : DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
FULL_WORD_MULTIPLIER(fullWordMultiplier), // TODO : remove this variable.
ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) { ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
AKLOGI("UnigramDictionary - constructor"); AKLOGI("UnigramDictionary - constructor");

View File

@ -39,8 +39,8 @@ class UnigramDictionary {
static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0; static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0;
static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1; static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1;
static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2; static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2;
UnigramDictionary(const uint8_t *const streamStart, int fullWordMultiplier, int maxWordLength, UnigramDictionary(const uint8_t *const streamStart, int maxWordLength, int maxWords,
int maxWords, const unsigned int flags); const unsigned int flags);
int getFrequency(const int *const inWord, const int length) const; int getFrequency(const int *const inWord, const int length) const;
int getBigramPosition(int pos, int *word, int offset, int length) const; int getBigramPosition(int pos, int *word, int offset, int length) const;
int getSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates, int getSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
@ -114,7 +114,6 @@ class UnigramDictionary {
const uint8_t *const DICT_ROOT; const uint8_t *const DICT_ROOT;
const int MAX_WORD_LENGTH; const int MAX_WORD_LENGTH;
const int MAX_WORDS; const int MAX_WORDS;
const int FULL_WORD_MULTIPLIER;
const int ROOT_POS; const int ROOT_POS;
const int MAX_DIGRAPH_SEARCH_DEPTH; const int MAX_DIGRAPH_SEARCH_DEPTH;
const int FLAGS; const int FLAGS;