diff options
Diffstat (limited to 'native/jni/src')
-rw-r--r-- | native/jni/src/correction.cpp | 16 | ||||
-rw-r--r-- | native/jni/src/defines.h | 21 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.cpp | 36 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.h | 4 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.cpp | 14 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state_utils.h | 3 |
6 files changed, 36 insertions, 58 deletions
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index b8690eb94..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) { @@ -221,7 +221,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons --mExcessiveCount; mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0); - } else if (matchId == NEAR_PROXIMITY_CHAR) { + } else if (matchId == PROXIMITY_CHAR) { mLastCharExceeded = false; --mExcessiveCount; ++mProximityCount; @@ -299,11 +299,11 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons : (noCorrectionsHappenedSoFar && mProximityCount == 0); ProximityType matchedProximityCharId = secondTransposing - ? EQUIVALENT_CHAR + ? 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 @@ -332,7 +332,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(const int c, cons } } - if (UNRELATED_CHAR == matchedProximityCharId + if (SUBSTITUTION_CHAR == matchedProximityCharId || ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) { if (ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) { mAdditionalProximityMatching = true; @@ -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->getProximityType(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/defines.h b/native/jni/src/defines.h index 11dc3d20e..0aedc287f 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -275,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) @@ -396,15 +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, - // It is an unrelated char and could be a substitution char - UNRELATED_CHAR, - // It is an unrelated char nor a substitution char - UNRELATED_NOR_SUBSTITUTION_CHAR, + PROXIMITY_CHAR, // Additional proximity char which can differ by language. - ADDITIONAL_PROXIMITY_CHAR + ADDITIONAL_PROXIMITY_CHAR, + // It is a substitution char + SUBSTITUTION_CHAR, + // It is an unrelated char + UNRELATED_CHAR, } ProximityType; typedef enum { @@ -415,15 +415,16 @@ typedef enum { typedef enum { CT_MATCH, + CT_PROXIMITY, + CT_ADDITIONAL_PROXIMITY, + CT_SUBSTITUTION, CT_OMISSION, CT_INSERTION, CT_TRANSPOSITION, - CT_SUBSTITUTION, CT_SPACE_SUBSTITUTION, CT_SPACE_OMISSION, CT_COMPLETION, CT_TERMINAL, CT_NEW_WORD, - CT_NEW_WORD_BIGRAM, } CorrectionType; #endif // LATINIME_DEFINES_H diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index 00e7ffc6c..fe1c43320 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -156,15 +156,14 @@ 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; @@ -173,19 +172,10 @@ float ProximityInfoState::getPointToKeyLength( return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); } -float ProximityInfoState::getPointToKeyLength_G(const int inputIndex, const int codePoint) const { - return getPointToKeyLength(inputIndex, codePoint, 1.0f); -} - -// 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. @@ -207,15 +197,15 @@ ProximityType ProximityInfoState::getProximityType(const int index, const int co // 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 == codePoint) { - return EQUIVALENT_CHAR; + 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 @@ -228,7 +218,7 @@ ProximityType ProximityInfoState::getProximityType(const int index, const int co if (proximityIndex) { *proximityIndex = j; } - return NEAR_PROXIMITY_CHAR; + return PROXIMITY_CHAR; } ++j; } @@ -248,23 +238,23 @@ ProximityType ProximityInfoState::getProximityType(const int index, const int co ++j; } } - // Was not included, signal this as an unrelated character. - return UNRELATED_CHAR; + // 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_NOR_SUBSTITUTION_CHAR; + 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 EQUIVALENT_CHAR; + return MATCH_CHAR; } } - return UNRELATED_NOR_SUBSTITUTION_CHAR; + return UNRELATED_CHAR; } bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const { diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index dd1eb764f..224240b00 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -147,10 +147,8 @@ 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 getProximityType(const int index, const int codePoint, const bool checkProximityChars, int *proximityIndex = 0) const; diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp index 2ca39f9e3..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,27 +634,19 @@ 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_VALUE_FOR_WEIGHTING); } -/* 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); -} - // Updates probabilities of aligning to some keys and skipping. // Word suggestion should be based on this probabilities. /* static */ void ProximityInfoStateUtils::updateAlignPointProbabilities( 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, |