aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/proximity_info_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src/proximity_info_state.cpp')
-rw-r--r--native/jni/src/proximity_info_state.cpp64
1 files changed, 37 insertions, 27 deletions
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