aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src')
-rw-r--r--native/jni/src/binary_format.h4
-rw-r--r--native/jni/src/proximity_info_state.cpp43
-rw-r--r--native/jni/src/proximity_info_state.h15
-rw-r--r--native/jni/src/unigram_dictionary.cpp8
4 files changed, 37 insertions, 33 deletions
diff --git a/native/jni/src/binary_format.h b/native/jni/src/binary_format.h
index 5d8b2a0f2..eec52e323 100644
--- a/native/jni/src/binary_format.h
+++ b/native/jni/src/binary_format.h
@@ -360,7 +360,7 @@ inline int BinaryFormat::getTerminalPosition(const uint8_t *const root,
while (true) {
// If we already traversed the tree further than the word is long, there means
// there was no match (or we would have found it).
- if (wordPos > length) return NOT_VALID_WORD;
+ if (wordPos >= length) return NOT_VALID_WORD;
int charGroupCount = BinaryFormat::getGroupCountAndForwardPointer(root, &pos);
const int32_t wChar = forceLowerCaseSearch ? toLowerCase(inWord[wordPos]) : inWord[wordPos];
while (true) {
@@ -383,7 +383,7 @@ inline int BinaryFormat::getTerminalPosition(const uint8_t *const root,
// character that does not match, as explained above, it means the word is
// not in the dictionary (by virtue of this chargroup being the only one to
// match the word on the first character, but not matching the whole word).
- if (wordPos > length) return NOT_VALID_WORD;
+ if (wordPos >= length) return NOT_VALID_WORD;
if (inWord[wordPos] != character) return NOT_VALID_WORD;
character = BinaryFormat::getCodePointAndForwardPointer(root, &pos);
}
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index b363dcc36..c62b9b35d 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -224,7 +224,7 @@ float ProximityInfoState::updateNearKeysDistances(const int x, const int y,
bool ProximityInfoState::isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances,
const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances) const {
- static const float MARGIN = 0.5f;
+ static const float MARGIN = 0.05f;
for (NearKeysDistanceMap::const_iterator it = prevNearKeysDistances->begin();
it != prevNearKeysDistances->end(); ++it) {
@@ -245,14 +245,14 @@ float ProximityInfoState::getPointScore(
const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances) const {
static const float BASE_SAMPLE_RATE_SCALE = 0.1f;
- static const float SAVE_DISTANCE_SCALE = 12.0f;
+ static const float SAVE_DISTANCE_SCALE = 14.0f;
static const float SAVE_DISTANCE_SCORE = 2.0f;
static const float SKIP_DISTANCE_SCALE = 1.5f;
static const float SKIP_DISTANCE_SCORE = -1.0f;
- static const float CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE = 2.5f;
+ static const float CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE = 3.5f;
static const float CHECK_LOCALMIN_DISTANCE_SCORE = -1.0f;
static const float STRAIGHT_ANGLE_THRESHOLD = M_PI_F / 32.0f;
- static const float STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE = 4.0f;
+ static const float STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE = 5.0f;
static const float STRAIGHT_SKIP_NEAREST_DISTANCE_THRESHOLD = 0.5f;
static const float STRAIGHT_SKIP_SCORE = -1.0f;
@@ -275,19 +275,19 @@ float ProximityInfoState::getPointScore(
score += SKIP_DISTANCE_SCORE;
}
// Location
- if (!isPrevLocalMin(currentNearKeysDistances, currentNearKeysDistances,
+ if (distPrev < baseSampleRate * CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE) {
+ if (!isPrevLocalMin(currentNearKeysDistances, currentNearKeysDistances,
prevPrevNearKeysDistances)) {
- if (distPrev < baseSampleRate * CHECK_LOCALMIN_DISTANCE_THRESHOLD_SCALE) {
score += CHECK_LOCALMIN_DISTANCE_SCORE;
}
}
// Angle
- const float angle1 = getAngle(x, y, mInputXs.back(), mInputYs.back());
- const float angle2 = getAngle(mInputXs.back(), mInputYs.back(),
- mInputXs[size - 2], mInputYs[size - 2]);
- if (getAngleDiff(angle1, angle2) < STRAIGHT_ANGLE_THRESHOLD) {
- if (nearest > STRAIGHT_SKIP_NEAREST_DISTANCE_THRESHOLD
- && distPrev < baseSampleRate * STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE) {
+ if (nearest > STRAIGHT_SKIP_NEAREST_DISTANCE_THRESHOLD
+ && distPrev < baseSampleRate * STRAIGHT_SKIP_DISTANCE_THRESHOLD_SCALE) {
+ const float angle1 = getAngle(x, y, mInputXs.back(), mInputYs.back());
+ const float angle2 = getAngle(mInputXs.back(), mInputYs.back(),
+ mInputXs[size - 2], mInputYs[size - 2]);
+ if (getAngleDiff(angle1, angle2) < STRAIGHT_ANGLE_THRESHOLD) {
score += STRAIGHT_SKIP_SCORE;
}
}
@@ -383,13 +383,14 @@ float ProximityInfoState::calculateNormalizedSquaredDistance(
}
int ProximityInfoState::getDuration(const int index) const {
- if (mInputSize > 0 && index > 0 && index < static_cast<int>(mInputSize) - 1) {
+ if (mInputSize > 0 && index > 0 && index < mInputSize - 1) {
return mTimes[index + 1] - mTimes[index - 1];
}
return 0;
}
-float ProximityInfoState::getPointToKeyLength(int inputIndex, int codePoint, float scale) {
+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;
@@ -404,11 +405,7 @@ float ProximityInfoState::getPointToKeyLength(int inputIndex, int codePoint, flo
return MAX_POINT_TO_KEY_LENGTH;
}
-int ProximityInfoState::getKeyKeyDistance(int key0, int key1) {
- return mProximityInfo->getKeyKeyDistanceG(key0, key1);
-}
-
-int ProximityInfoState::getSpaceY() {
+int ProximityInfoState::getSpaceY() const {
const int keyId = mProximityInfo->getKeyIndexOf(' ');
return mProximityInfo->getKeyCenterYOfKeyIdG(keyId);
}
@@ -447,4 +444,12 @@ int32_t ProximityInfoState::getAllPossibleChars(
}
return i;
}
+
+float ProximityInfoState::getAveragePointDuration() const {
+ if (mInputSize == 0) {
+ return 0;
+ }
+ return (mTimes[mInputSize - 1] - mTimes[0]) / static_cast<float>(mInputSize);
+}
+
} // namespace latinime
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index 80b84e962..1d5777347 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -200,27 +200,26 @@ class ProximityInfoState {
return mInputSize;
}
- int getInputX(int index) const {
+ int getInputX(const int index) const {
return mInputXs[index];
}
- int getInputY(int index) const {
+ int getInputY(const int index) const {
return mInputYs[index];
}
- int getLengthCache(int index) const {
+ int getLengthCache(const int index) const {
return mLengthCache[index];
}
- float getPointToKeyLength(int inputIndex, int charCode, float scale);
+ float getPointToKeyLength(const int inputIndex, const int charCode, const float scale) const;
- int getKeyKeyDistance(int key0, int key1);
-
- int getSpaceY();
+ int getSpaceY() const;
int32_t getAllPossibleChars(
- const size_t startIndex, int32_t *const filter, int32_t filterSize) const;
+ const size_t startIndex, int32_t *const filter, const int32_t filterSize) const;
+ float getAveragePointDuration() const;
private:
DISALLOW_COPY_AND_ASSIGN(ProximityInfoState);
typedef hash_map_compat<int, float> NearKeysDistanceMap;
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp
index b7e245a6c..cf806c111 100644
--- a/native/jni/src/unigram_dictionary.cpp
+++ b/native/jni/src/unigram_dictionary.cpp
@@ -451,7 +451,7 @@ int UnigramDictionary::getSubStringSuggestion(
const bool hasAutoCorrectionCandidate, const int currentWordIndex,
const int inputWordStartPos, const int inputWordLength,
const int outputWordStartPos, const bool isSpaceProximity, int *freqArray,
- int*wordLengthArray, unsigned short *outputWord, int *outputWordLength) const {
+ int *wordLengthArray, unsigned short *outputWord, int *outputWordLength) const {
if (inputWordLength > MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH) {
return FLAG_MULTIPLE_SUGGEST_ABORT;
}
@@ -546,9 +546,9 @@ int UnigramDictionary::getSubStringSuggestion(
freq = score >> (nextWordLength + TWO_WORDS_PLUS_OTHER_ERROR_CORRECTION_DEMOTION_DIVIDER);
}
if (DEBUG_DICT) {
- AKLOGI("Freq(%d): %d, length: %d, input length: %d, input start: %d (%d)"
- , currentWordIndex, freq, nextWordLength, inputWordLength, inputWordStartPos,
- wordLengthArray[0]);
+ AKLOGI("Freq(%d): %d, length: %d, input length: %d, input start: %d (%d)",
+ currentWordIndex, freq, nextWordLength, inputWordLength, inputWordStartPos,
+ (currentWordIndex > 0) ? wordLengthArray[0] : 0);
}
if (freq <= 0 || nextWordLength <= 0
|| MAX_WORD_LENGTH <= (outputWordStartPos + nextWordLength)) {