diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/jni/src/char_utils.cpp | 6 | ||||
-rw-r--r-- | native/jni/src/correction.cpp | 38 | ||||
-rw-r--r-- | native/jni/src/correction.h | 2 | ||||
-rw-r--r-- | native/jni/src/defines.h | 37 | ||||
-rw-r--r-- | native/jni/src/proximity_info.cpp | 2 | ||||
-rw-r--r-- | native/jni/src/proximity_info.h | 8 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.cpp | 64 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.h | 8 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.cpp | 20 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.h | 3 | ||||
-rw-r--r-- | native/jni/src/proximity_info_utils.h | 2 |
11 files changed, 109 insertions, 81 deletions
diff --git a/native/jni/src/char_utils.cpp b/native/jni/src/char_utils.cpp index f1148f4d4..8d917ea74 100644 --- a/native/jni/src/char_utils.cpp +++ b/native/jni/src/char_utils.cpp @@ -1070,12 +1070,14 @@ const unsigned short BASE_CHARS[BASE_CHARS_SIZE] = { /* U+0418 */ 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, // U+0419: Manually changed from 0418 to 0419 /* U+0420 */ 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, - /* U+0428 */ 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, + /* U+0428 */ 0x0428, 0x0429, 0x042C, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, + // U+042A: Manually changed from 042A to 042C /* U+0430 */ 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, /* U+0438 */ 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, // U+0439: Manually changed from 0438 to 0439 /* U+0440 */ 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, - /* U+0448 */ 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, + /* U+0448 */ 0x0448, 0x0449, 0x044C, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, + // U+044A: Manually changed from 044A to 044C /* U+0450 */ 0x0435, 0x0435, 0x0452, 0x0433, 0x0454, 0x0455, 0x0456, 0x0456, /* U+0458 */ 0x0458, 0x0459, 0x045A, 0x045B, 0x043A, 0x0438, 0x0443, 0x045F, /* U+0460 */ 0x0460, 0x0461, 0x0462, 0x0463, 0x0464, 0x0465, 0x0466, 0x0467, diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index d4bd4aa00..0ae02d506 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -190,11 +190,11 @@ bool Correction::needsToPrune() const { } inline static bool isEquivalentChar(ProximityType type) { - return type == EQUIVALENT_CHAR; + return type == MATCH_CHAR; } inline static bool isProximityCharOrEquivalentChar(ProximityType type) { - return type == EQUIVALENT_CHAR || type == NEAR_PROXIMITY_CHAR; + return type == MATCH_CHAR || type == PROXIMITY_CHAR; } Correction::CorrectionType Correction::processCharAndCalcState(const int c, const bool isTerminal) { @@ -214,14 +214,14 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons bool incremented = false; if (mLastCharExceeded && mInputIndex == mInputSize - 1) { // TODO: Do not check the proximity if EditDistance exceeds the threshold - const ProximityType matchId = mProximityInfoState.getMatchedProximityId( + const ProximityType matchId = mProximityInfoState.getProximityType( mInputIndex, c, true, &proximityIndex); if (isEquivalentChar(matchId)) { mLastCharExceeded = false; --mExcessiveCount; mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0); - } else if (matchId == NEAR_PROXIMITY_CHAR) { + } else if (matchId == PROXIMITY_CHAR) { mLastCharExceeded = false; --mExcessiveCount; ++mProximityCount; @@ -268,7 +268,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons bool secondTransposing = false; if (mTransposedCount % 2 == 1) { - if (isEquivalentChar(mProximityInfoState.getMatchedProximityId( + if (isEquivalentChar(mProximityInfoState.getProximityType( mInputIndex - 1, c, false))) { ++mTransposedCount; secondTransposing = true; @@ -299,16 +299,16 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons : (noCorrectionsHappenedSoFar && mProximityCount == 0); ProximityType matchedProximityCharId = secondTransposing - ? EQUIVALENT_CHAR - : mProximityInfoState.getMatchedProximityId( + ? MATCH_CHAR + : mProximityInfoState.getProximityType( mInputIndex, c, checkProximityChars, &proximityIndex); - if (UNRELATED_CHAR == matchedProximityCharId + if (SUBSTITUTION_CHAR == matchedProximityCharId || ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) { if (canTryCorrection && mOutputIndex > 0 && mCorrectionStates[mOutputIndex].mProximityMatching && mCorrectionStates[mOutputIndex].mExceeding - && isEquivalentChar(mProximityInfoState.getMatchedProximityId( + && isEquivalentChar(mProximityInfoState.getProximityType( mInputIndex, mWord[mOutputIndex - 1], false))) { if (DEBUG_CORRECTION && (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputSize) @@ -327,12 +327,12 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons // Here, we are doing something equivalent to matchedProximityCharId, // but we already know that "excessive char correction" just happened // so that we just need to check "mProximityCount == 0". - matchedProximityCharId = mProximityInfoState.getMatchedProximityId( + matchedProximityCharId = mProximityInfoState.getProximityType( mInputIndex, c, mProximityCount == 0, &proximityIndex); } } - if (UNRELATED_CHAR == matchedProximityCharId + if (SUBSTITUTION_CHAR == matchedProximityCharId || ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) { if (ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) { mAdditionalProximityMatching = true; @@ -344,10 +344,10 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons if (mInputIndex < mInputSize - 1 && mOutputIndex > 0 && mTransposedCount > 0 && !mCorrectionStates[mOutputIndex].mTransposing && mCorrectionStates[mOutputIndex - 1].mTransposing - && isEquivalentChar(mProximityInfoState.getMatchedProximityId( + && isEquivalentChar(mProximityInfoState.getProximityType( mInputIndex, mWord[mOutputIndex - 1], false)) && isEquivalentChar( - mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) { + mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) { // Conversion t->e // Example: // occaisional -> occa sional @@ -359,7 +359,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons && !mCorrectionStates[mOutputIndex].mTransposing && mCorrectionStates[mOutputIndex - 1].mTransposing && isEquivalentChar( - mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) { + mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) { // Conversion t->s // Example: // chcolate -> chocolate @@ -371,7 +371,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons && mCorrectionStates[mOutputIndex].mProximityMatching && mCorrectionStates[mOutputIndex].mSkipping && isEquivalentChar( - mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) { + mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) { // Conversion p->s // Note: This logic tries saving cases like contrst --> contrast -- "a" is one of // proximity chars of "s", but it should rather be handled as a skipped char. @@ -383,7 +383,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons && mCorrectionStates[mOutputIndex].mSkipping && mCorrectionStates[mOutputIndex].mAdditionalProximityMatching && isProximityCharOrEquivalentChar( - mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) { + mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) { // Conversion s->a incrementInputIndex(); --mSkippedCount; @@ -392,7 +392,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO; } else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputSize && isEquivalentChar( - mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) { + mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) { // 1.2. Excessive or transpose correction if (mTransposing) { ++mTransposedCount; @@ -455,7 +455,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons mMatching = true; ++mEquivalentCharCount; mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0); - } else if (NEAR_PROXIMITY_CHAR == matchedProximityCharId) { + } else if (PROXIMITY_CHAR == matchedProximityCharId) { mProximityMatching = true; ++mProximityCount; mDistances[mOutputIndex] = @@ -614,7 +614,7 @@ inline static bool isUpperCase(unsigned short c) { multiplyIntCapped(matchWeight, &finalFreq); } - if (proximityInfoState->getMatchedProximityId(0, word[0], true) == UNRELATED_CHAR) { + if (proximityInfoState->getProximityType(0, word[0], true) == SUBSTITUTION_CHAR) { multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq); } diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h index 34f794d84..f0d62102f 100644 --- a/native/jni/src/correction.h +++ b/native/jni/src/correction.h @@ -119,7 +119,7 @@ class Correction { // proximity info state void initInputParams(const ProximityInfo *proximityInfo, const int *inputCodes, const int inputSize, const int *xCoordinates, const int *yCoordinates) { - mProximityInfoState.initInputParams(0, MAX_POINT_TO_KEY_LENGTH, + mProximityInfoState.initInputParams(0, static_cast<float>(MAX_VALUE_FOR_WEIGHTING), proximityInfo, inputCodes, inputSize, xCoordinates, yCoordinates, 0, 0, false); } diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index a1fdae7a4..0aedc287f 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -214,6 +214,8 @@ static inline void prof_out(void) { #define DEBUG_SAMPLING_POINTS false #define DEBUG_POINTS_PROBABILITY false #define DEBUG_DOUBLE_LETTER false +#define DEBUG_CACHE false +#define DEBUG_DUMP_ERROR false #ifdef FLAG_FULL_DBG #define DEBUG_GEO_FULL true @@ -237,6 +239,8 @@ static inline void prof_out(void) { #define DEBUG_SAMPLING_POINTS false #define DEBUG_POINTS_PROBABILITY false #define DEBUG_DOUBLE_LETTER false +#define DEBUG_CACHE false +#define DEBUG_DUMP_ERROR false #define DEBUG_GEO_FULL false @@ -271,7 +275,7 @@ static inline void prof_out(void) { #define NOT_A_CODE_POINT (-1) #define NOT_A_DISTANCE (-1) #define NOT_A_COORDINATE (-1) -#define EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO (-2) +#define MATCH_CHAR_WITHOUT_DISTANCE_INFO (-2) #define PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO (-3) #define ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO (-4) #define NOT_AN_INDEX (-1) @@ -283,6 +287,7 @@ static inline void prof_out(void) { #define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true #define SUGGEST_MULTIPLE_WORDS true +#define SUGGEST_INTERFACE_OUTPUT_SCALE 1000000.0f // The following "rate"s are used as a multiplier before dividing by 100, so they are in percent. #define WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE 80 @@ -336,8 +341,9 @@ static inline void prof_out(void) { #define MAX_DEPTH_MULTIPLIER 3 #define FIRST_WORD_INDEX 0 -// Max Distance between point to key -#define MAX_POINT_TO_KEY_LENGTH 10000000 +// Max value for length, distance and probability which are used in weighting +// TODO: Remove +#define MAX_VALUE_FOR_WEIGHTING 10000000 // The max number of the keys in one keyboard layout #define MAX_KEY_COUNT_IN_A_KEYBOARD 64 @@ -390,13 +396,15 @@ template<typename T> AK_FORCE_INLINE const T &max(const T &a, const T &b) { retu // Used as a return value for character comparison typedef enum { // Same char, possibly with different case or accent - EQUIVALENT_CHAR, + MATCH_CHAR, // It is a char located nearby on the keyboard - NEAR_PROXIMITY_CHAR, + PROXIMITY_CHAR, + // Additional proximity char which can differ by language. + ADDITIONAL_PROXIMITY_CHAR, + // It is a substitution char + SUBSTITUTION_CHAR, // It is an unrelated char UNRELATED_CHAR, - // Additional proximity char which can differ by language. - ADDITIONAL_PROXIMITY_CHAR } ProximityType; typedef enum { @@ -404,4 +412,19 @@ typedef enum { A_DOUBLE_LETTER, A_STRONG_DOUBLE_LETTER } DoubleLetterLevel; + +typedef enum { + CT_MATCH, + CT_PROXIMITY, + CT_ADDITIONAL_PROXIMITY, + CT_SUBSTITUTION, + CT_OMISSION, + CT_INSERTION, + CT_TRANSPOSITION, + CT_SPACE_SUBSTITUTION, + CT_SPACE_OMISSION, + CT_COMPLETION, + CT_TERMINAL, + CT_NEW_WORD, +} CorrectionType; #endif // LATINIME_DEFINES_H diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp index 81eb0b37d..74b5e0131 100644 --- a/native/jni/src/proximity_info.cpp +++ b/native/jni/src/proximity_info.cpp @@ -204,6 +204,6 @@ int ProximityInfo::getKeyKeyDistanceG(const int keyId0, const int keyId1) const if (keyId0 >= 0 && keyId1 >= 0) { return mKeyKeyDistancesG[keyId0][keyId1]; } - return MAX_POINT_TO_KEY_LENGTH; + return MAX_VALUE_FOR_WEIGHTING; } } // namespace latinime diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h index 22bbdf165..57a175d2c 100644 --- a/native/jni/src/proximity_info.h +++ b/native/jni/src/proximity_info.h @@ -70,7 +70,7 @@ class ProximityInfo { int getKeyCenterYOfKeyIdG(int keyId) const; int getKeyKeyDistanceG(int keyId0, int keyId1) const; - void AK_FORCE_INLINE initializeProximities(const int *const inputCodes, + AK_FORCE_INLINE void initializeProximities(const int *const inputCodes, const int *const inputXCoordinates, const int *const inputYCoordinates, const int inputSize, int *allInputCodes) const { ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates, @@ -79,10 +79,14 @@ class ProximityInfo { KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes); } - int AK_FORCE_INLINE getKeyIndexOf(const int c) const { + AK_FORCE_INLINE int getKeyIndexOf(const int c) const { return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap); } + AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const { + return getKeyIndexOf(codePoint) != NOT_AN_INDEX; + } + private: DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo); diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index bdbf8b170..fe1c43320 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -36,6 +36,9 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi mIsContinuationPossible = ProximityInfoStateUtils::checkAndReturnIsContinuationPossible( inputSize, xCoordinates, yCoordinates, times, mSampledInputSize, &mSampledInputXs, &mSampledInputYs, &mSampledTimes, &mSampledInputIndice); + if (DEBUG_DICT) { + AKLOGI("isContinuationPossible = %s", (mIsContinuationPossible ? "true" : "false")); + } mProximityInfo = proximityInfo; mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData(); @@ -153,36 +156,26 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi } } -// TODO: Remove the "scale" parameter // This function basically converts from a length to an edit distance. Accordingly, it's obviously // wrong to compare with mMaxPointToKeyLength. float ProximityInfoState::getPointToKeyLength( - const int inputIndex, const int codePoint, const float scale) const { + const int inputIndex, const int codePoint) const { const int keyId = mProximityInfo->getKeyIndexOf(codePoint); if (keyId != NOT_AN_INDEX) { const int index = inputIndex * mProximityInfo->getKeyCount() + keyId; - return min(mSampledDistanceCache_G[index] * scale, mMaxPointToKeyLength); + return min(mSampledDistanceCache_G[index], mMaxPointToKeyLength); } if (isSkippableCodePoint(codePoint)) { return 0.0f; } // If the char is not a key on the keyboard then return the max length. - return MAX_POINT_TO_KEY_LENGTH; -} - -float ProximityInfoState::getPointToKeyLength_G(const int inputIndex, const int codePoint) const { - return getPointToKeyLength(inputIndex, codePoint, 1.0f); + return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); } -// TODO: Remove the "scale" parameter float ProximityInfoState::getPointToKeyByIdLength( - const int inputIndex, const int keyId, const float scale) const { + const int inputIndex, const int keyId) const { return ProximityInfoStateUtils::getPointToKeyByIdLength(mMaxPointToKeyLength, - &mSampledDistanceCache_G, mProximityInfo->getKeyCount(), inputIndex, keyId, scale); -} - -float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const int keyId) const { - return getPointToKeyByIdLength(inputIndex, keyId, 1.0f); + &mSampledDistanceCache_G, mProximityInfo->getKeyCount(), inputIndex, keyId); } // In the following function, c is the current character of the dictionary word currently examined. @@ -190,41 +183,42 @@ float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const in // the same position. We want to see if c is in it: if so, then the word contains at that position // a character close to what the user typed. // What the user typed is actually the first character of the array. -// proximityIndex is a pointer to the variable where getMatchedProximityId returns the index of c +// proximityIndex is a pointer to the variable where getProximityType returns the index of c // in the proximity chars of the input index. // Notice : accented characters do not have a proximity list, so they are alone in their list. The // non-accented version of the character should be considered "close", but not the other keys close // to the non-accented version. -ProximityType ProximityInfoState::getMatchedProximityId(const int index, const int c, +ProximityType ProximityInfoState::getProximityType(const int index, const int codePoint, const bool checkProximityChars, int *proximityIndex) const { const int *currentCodePoints = getProximityCodePointsAt(index); const int firstCodePoint = currentCodePoints[0]; - const int baseLowerC = toBaseLowerCase(c); + const int baseLowerC = toBaseLowerCase(codePoint); // The first char in the array is what user typed. If it matches right away, that means the // user typed that same char for this pos. - if (firstCodePoint == baseLowerC || firstCodePoint == c) { - return EQUIVALENT_CHAR; + if (firstCodePoint == baseLowerC || firstCodePoint == codePoint) { + return MATCH_CHAR; } - if (!checkProximityChars) return UNRELATED_CHAR; + if (!checkProximityChars) return SUBSTITUTION_CHAR; // If the non-accented, lowercased version of that first character matches c, then we have a // non-accented version of the accented character the user typed. Treat it as a close char. if (toBaseLowerCase(firstCodePoint) == baseLowerC) { - return NEAR_PROXIMITY_CHAR; + return PROXIMITY_CHAR; } // Not an exact nor an accent-alike match: search the list of close keys int j = 1; while (j < MAX_PROXIMITY_CHARS_SIZE && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { - const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c); + const bool matched = (currentCodePoints[j] == baseLowerC + || currentCodePoints[j] == codePoint); if (matched) { if (proximityIndex) { *proximityIndex = j; } - return NEAR_PROXIMITY_CHAR; + return PROXIMITY_CHAR; } ++j; } @@ -233,7 +227,8 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i ++j; while (j < MAX_PROXIMITY_CHARS_SIZE && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { - const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c); + const bool matched = (currentCodePoints[j] == baseLowerC + || currentCodePoints[j] == codePoint); if (matched) { if (proximityIndex) { *proximityIndex = j; @@ -243,7 +238,22 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i ++j; } } - // Was not included, signal this as an unrelated character. + // Was not included, signal this as a substitution character. + return SUBSTITUTION_CHAR; +} + +ProximityType ProximityInfoState::getProximityTypeG(const int index, const int codePoint) const { + if (!isUsed()) { + return UNRELATED_CHAR; + } + const int lowerCodePoint = toLowerCase(codePoint); + const int baseLowerCodePoint = toBaseCodePoint(lowerCodePoint); + for (int i = 0; i < static_cast<int>(mSampledSearchKeyVectors[index].size()); ++i) { + if (mSampledSearchKeyVectors[index][i] == lowerCodePoint + || mSampledSearchKeyVectors[index][i] == baseLowerCodePoint) { + return MATCH_CHAR; + } + } return UNRELATED_CHAR; } @@ -294,6 +304,6 @@ float ProximityInfoState::getProbability(const int index, const int keyIndex) co if (it != mCharProbabilities[index].end()) { return it->second; } - return static_cast<float>(MAX_POINT_TO_KEY_LENGTH); + return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); } } // namespace latinime diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index c4cbd582d..224240b00 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -147,14 +147,14 @@ class ProximityInfoState { return mIsContinuationPossible; } - float getPointToKeyByIdLength(const int inputIndex, const int keyId, const float scale) const; float getPointToKeyByIdLength(const int inputIndex, const int keyId) const; - float getPointToKeyLength(const int inputIndex, const int codePoint, const float scale) const; - float getPointToKeyLength_G(const int inputIndex, const int codePoint) const; + float getPointToKeyLength(const int inputIndex, const int codePoint) const; - ProximityType getMatchedProximityId(const int index, const int c, + ProximityType getProximityType(const int index, const int codePoint, const bool checkProximityChars, int *proximityIndex = 0) const; + ProximityType getProximityTypeG(const int index, const int codePoint) const; + const std::vector<int> *getSearchKeyVector(const int index) const { return &mSampledSearchKeyVectors[index]; } diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp index 2bf327fcc..ccb28bc8c 100644 --- a/native/jni/src/proximity_info_state_utils.cpp +++ b/native/jni/src/proximity_info_state_utils.cpp @@ -209,7 +209,7 @@ namespace latinime { * ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR); } else { normalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] = - (j == 0) ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO : + (j == 0) ? MATCH_CHAR_WITHOUT_DISTANCE_INFO : PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO; } if (DEBUG_PROXIMITY_CHARS) { @@ -634,25 +634,17 @@ namespace latinime { return getAngleDiff(previousDirection, nextDirection); } -// TODO: Remove the "scale" parameter // This function basically converts from a length to an edit distance. Accordingly, it's obviously // wrong to compare with mMaxPointToKeyLength. /* static */ float ProximityInfoStateUtils::getPointToKeyByIdLength(const float maxPointToKeyLength, const std::vector<float> *const SampledDistanceCache_G, const int keyCount, - const int inputIndex, const int keyId, const float scale) { + const int inputIndex, const int keyId) { if (keyId != NOT_AN_INDEX) { const int index = inputIndex * keyCount + keyId; - return min((*SampledDistanceCache_G)[index] * scale, maxPointToKeyLength); + return min((*SampledDistanceCache_G)[index], maxPointToKeyLength); } // If the char is not a key on the keyboard then return the max length. - return static_cast<float>(MAX_POINT_TO_KEY_LENGTH); -} - -/* static */ float ProximityInfoStateUtils::getPointToKeyByIdLength(const float maxPointToKeyLength, - const std::vector<float> *const SampledDistanceCache_G, const int keyCount, - const int inputIndex, const int keyId) { - return getPointToKeyByIdLength( - maxPointToKeyLength, SampledDistanceCache_G, keyCount, inputIndex, keyId, 1.0f); + return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); } // Updates probabilities of aligning to some keys and skipping. @@ -678,7 +670,7 @@ namespace latinime { const float currentAngle = getPointAngle(sampledInputXs, sampledInputYs, i); const float speedRate = (*sampledSpeedRates)[i]; - float nearestKeyDistance = static_cast<float>(MAX_POINT_TO_KEY_LENGTH); + float nearestKeyDistance = static_cast<float>(MAX_VALUE_FOR_WEIGHTING); for (int j = 0; j < keyCount; ++j) { if ((*SampledNearKeySets)[i].test(j)) { const float distance = getPointToKeyByIdLength( @@ -1016,7 +1008,7 @@ namespace latinime { float sumLogProbability = 0.0f; // TODO: Current implementation is greedy algorithm. DP would be efficient for many cases. for (int i = 0; i < sampledInputSize && index < MAX_WORD_LENGTH - 1; ++i) { - float minLogProbability = static_cast<float>(MAX_POINT_TO_KEY_LENGTH); + float minLogProbability = static_cast<float>(MAX_VALUE_FOR_WEIGHTING); int character = NOT_AN_INDEX; for (hash_map_compat<int, float>::const_iterator it = (*charProbabilities)[i].begin(); it != (*charProbabilities)[i].end(); ++it) { diff --git a/native/jni/src/proximity_info_state_utils.h b/native/jni/src/proximity_info_state_utils.h index d55730aca..a7f4a3425 100644 --- a/native/jni/src/proximity_info_state_utils.h +++ b/native/jni/src/proximity_info_state_utils.h @@ -81,9 +81,6 @@ class ProximityInfoStateUtils { std::vector<std::vector<int> > *sampledSearchKeyVectors); static float getPointToKeyByIdLength(const float maxPointToKeyLength, const std::vector<float> *const SampledDistanceCache_G, const int keyCount, - const int inputIndex, const int keyId, const float scale); - static float getPointToKeyByIdLength(const float maxPointToKeyLength, - const std::vector<float> *const SampledDistanceCache_G, const int keyCount, const int inputIndex, const int keyId); static void initGeometricDistanceInfos(const ProximityInfo *const proximityInfo, const int sampledInputSize, const int lastSavedInputSize, diff --git a/native/jni/src/proximity_info_utils.h b/native/jni/src/proximity_info_utils.h index 51cafba2c..71c97e325 100644 --- a/native/jni/src/proximity_info_utils.h +++ b/native/jni/src/proximity_info_utils.h @@ -226,7 +226,7 @@ class ProximityInfoUtils { const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights, const int keyId, const int x, const int y) { // NOT_A_ID is -1, but return whenever < 0 just in case - if (keyId < 0) return MAX_POINT_TO_KEY_LENGTH; + if (keyId < 0) return MAX_VALUE_FOR_WEIGHTING; const int left = keyXCoordinates[keyId]; const int top = keyYCoordinates[keyId]; const int right = left + keyWidths[keyId]; |