diff options
Diffstat (limited to 'native/jni/src')
-rw-r--r-- | native/jni/src/correction.cpp | 9 | ||||
-rw-r--r-- | native/jni/src/correction.h | 5 | ||||
-rw-r--r-- | native/jni/src/defines.h | 4 | ||||
-rw-r--r-- | native/jni/src/proximity_info.cpp | 1 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.cpp | 56 | ||||
-rw-r--r-- | native/jni/src/proximity_info_state.h | 6 | ||||
-rw-r--r-- | native/jni/src/terminal_attributes.h | 1 |
7 files changed, 51 insertions, 31 deletions
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index 50f33fe23..46ca91105 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -14,11 +14,6 @@ * limitations under the License. */ -#include <cassert> -#include <cctype> -#include <cmath> -#include <cstring> - #define LOG_TAG "LatinIME: correction.cpp" #include "char_utils.h" @@ -1002,7 +997,7 @@ int Correction::RankingAlgorithm::editDistance(const int *before, const int befo float Correction::RankingAlgorithm::calcNormalizedScore(const int *before, const int beforeLength, const int *after, const int afterLength, const int score) { if (0 == beforeLength || 0 == afterLength) { - return 0; + return 0.0f; } const int distance = editDistance(before, beforeLength, after, afterLength); int spaceCount = 0; @@ -1013,7 +1008,7 @@ float Correction::RankingAlgorithm::calcNormalizedScore(const int *before, const } if (spaceCount == afterLength) { - return 0; + return 0.0f; } const float maxScore = score >= S_INT_MAX ? static_cast<float>(S_INT_MAX) diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h index 912cd838e..4184c6429 100644 --- a/native/jni/src/correction.h +++ b/native/jni/src/correction.h @@ -19,7 +19,6 @@ #include <cassert> #include <cstring> // for memset() -#include <stdint.h> #include "correction_state.h" #include "defines.h" @@ -237,7 +236,7 @@ class Correction { int mTerminalOutputIndex; int mMaxErrors; - uint8_t mTotalTraverseCount; + int mTotalTraverseCount; // The following arrays are state buffer. int mWord[MAX_WORD_LENGTH_INTERNAL]; @@ -352,7 +351,7 @@ AK_FORCE_INLINE static void calcEditDistanceOneStep(int *editDistanceTable, cons const int prevCO = outputLength >= 2 ? toBaseLowerCase(output[outputLength - 2]) : 0; for (int i = 1; i <= inputSize; ++i) { const int ci = toBaseLowerCase(input[i - 1]); - const uint16_t cost = (ci == co) ? 0 : 1; + const int cost = (ci == co) ? 0 : 1; current[i] = min(current[i - 1] + 1, min(prev[i] + 1, prev[i - 1] + cost)); if (i >= 2 && prevprev && ci == prevCO && co == toBaseLowerCase(input[i - 2])) { current[i] = min(current[i], prevprev[i - 2] + 1); diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index a6dd2fd84..90f714bec 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -237,9 +237,6 @@ static inline void prof_out(void) { #endif // FLAG_DBG -#ifndef U_SHORT_MAX -#define U_SHORT_MAX 65535 // ((1 << 16) - 1) -#endif #ifndef S_INT_MAX #define S_INT_MAX 2147483647 // ((1 << 31) - 1) #endif @@ -376,6 +373,7 @@ static inline void prof_out(void) { #define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3 // TODO: Remove +#define MAX_POINTER_COUNT 1 #define MAX_POINTER_COUNT_FOR_G 2 // Size, in bytes, of the bloom filter index for bigrams diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp index d38ea670c..ffe12ce49 100644 --- a/native/jni/src/proximity_info.cpp +++ b/native/jni/src/proximity_info.cpp @@ -15,7 +15,6 @@ */ #include <cassert> -#include <cmath> #include <cstring> #define LOG_TAG "LatinIME: proximity_info.cpp" diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp index 39d53fb52..549ac3544 100644 --- a/native/jni/src/proximity_info_state.cpp +++ b/native/jni/src/proximity_info_state.cpp @@ -39,12 +39,8 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize, const int *const xCoordinates, const int *const yCoordinates, const int *const times, const int *const pointerIds, const bool isGeometric) { - if (isGeometric) { - mIsContinuationPossible = checkAndReturnIsContinuationPossible( - inputSize, xCoordinates, yCoordinates, times); - } else { - mIsContinuationPossible = false; - } + mIsContinuationPossible = checkAndReturnIsContinuationPossible( + inputSize, xCoordinates, yCoordinates, times, isGeometric); mProximityInfo = proximityInfo; mHasTouchPositionCorrectionData = proximityInfo->hasTouchPositionCorrectionData(); @@ -466,13 +462,27 @@ float ProximityInfoState::calculateBeelineSpeedRate( } bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize, - const int *const xCoordinates, const int *const yCoordinates, const int *const times) { - for (int i = 0; i < mSampledInputSize; ++i) { - const int index = mInputIndice[i]; - if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] || - yCoordinates[index] != mSampledInputYs[i] || times[index] != mTimes[i]) { + const int *const xCoordinates, const int *const yCoordinates, const int *const times, + const bool isGeometric) const { + if (isGeometric) { + for (int i = 0; i < mSampledInputSize; ++i) { + const int index = mInputIndice[i]; + if (index > inputSize || xCoordinates[index] != mSampledInputXs[i] || + yCoordinates[index] != mSampledInputYs[i] || times[index] != mTimes[i]) { + return false; + } + } + } else { + if (inputSize < mSampledInputSize) { + // Assuming the cache is invalid if the previous input size is larger than the new one. return false; } + for (int i = 0; i < mSampledInputSize && i < MAX_WORD_LENGTH_INTERNAL; ++i) { + if (xCoordinates[i] != mSampledInputXs[i] + || yCoordinates[i] != mSampledInputYs[i]) { + return false; + } + } } return true; } @@ -658,11 +668,15 @@ int ProximityInfoState::getDuration(const int index) const { return 0; } -float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int codePoint) const { +// 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 keyId = mProximityInfo->getKeyIndexOf(codePoint); if (keyId != NOT_AN_INDEX) { const int index = inputIndex * mProximityInfo->getKeyCount() + keyId; - return min(mDistanceCache[index], mMaxPointToKeyLength); + return min(mDistanceCache[index] * scale, mMaxPointToKeyLength); } if (isSkippableCodePoint(codePoint)) { return 0.0f; @@ -671,15 +685,27 @@ float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int co return MAX_POINT_TO_KEY_LENGTH; } -float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const int keyId) const { +float ProximityInfoState::getPointToKeyLength(const int inputIndex, const int codePoint) const { + return getPointToKeyLength(inputIndex, codePoint, 1.0f); +} + +// 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::getPointToKeyByIdLength( + const int inputIndex, const int keyId, const float scale) const { if (keyId != NOT_AN_INDEX) { const int index = inputIndex * mProximityInfo->getKeyCount() + keyId; - return min(mDistanceCache[index], mMaxPointToKeyLength); + return min(mDistanceCache[index] * scale, mMaxPointToKeyLength); } // If the char is not a key on the keyboard then return the max length. return static_cast<float>(MAX_POINT_TO_KEY_LENGTH); } +float ProximityInfoState::getPointToKeyByIdLength(const int inputIndex, const int keyId) const { + return getPointToKeyByIdLength(inputIndex, keyId, 1.0f); +} + // In the following function, c is the current character of the dictionary word currently examined. // currentChars is an array containing the keys close to the character the user actually typed at // the same position. We want to see if c is in it: if so, then the word contains at that position diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h index d3b4062c8..b1ad3731e 100644 --- a/native/jni/src/proximity_info_state.h +++ b/native/jni/src/proximity_info_state.h @@ -155,8 +155,10 @@ class ProximityInfoState { return mIsContinuationPossible; } - float getPointToKeyLength(const int inputIndex, const int charCode) const; + 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(const int inputIndex, const int codePoint) const; ProximityType getMatchedProximityId(const int index, const int c, const bool checkProximityChars, int *proximityIndex = 0) const; @@ -242,7 +244,7 @@ class ProximityInfoState { const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances) const; bool checkAndReturnIsContinuationPossible(const int inputSize, const int *const xCoordinates, - const int *const yCoordinates, const int *const times); + const int *const yCoordinates, const int *const times, const bool isGeometric) const; void popInputData(); void updateAlignPointProbabilities(const int start); bool suppressCharProbabilities(const int index1, const int index2); diff --git a/native/jni/src/terminal_attributes.h b/native/jni/src/terminal_attributes.h index fed3c7251..6c2e0dce1 100644 --- a/native/jni/src/terminal_attributes.h +++ b/native/jni/src/terminal_attributes.h @@ -17,6 +17,7 @@ #ifndef LATINIME_TERMINAL_ATTRIBUTES_H #define LATINIME_TERMINAL_ATTRIBUTES_H +#include <stdint.h> #include "binary_format.h" namespace latinime { |