aboutsummaryrefslogtreecommitdiffstats
path: root/native/src/correction.cpp
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-09-29 03:58:27 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-29 03:58:27 -0700
commitdb096d681f40b8547b4ce83d07d8d8b54e30634e (patch)
tree22457810976009adb60571ce794ef679a4b998dd /native/src/correction.cpp
parenta45c6f24c3fe8ffc82cf0e80a0e808eb91dd2065 (diff)
parent40a5f6fa4df529bf21813d54fc20ffe5b3cbe436 (diff)
downloadlatinime-db096d681f40b8547b4ce83d07d8d8b54e30634e.tar.gz
latinime-db096d681f40b8547b4ce83d07d8d8b54e30634e.tar.xz
latinime-db096d681f40b8547b4ce83d07d8d8b54e30634e.zip
Merge "Add a flag to demote completed suggestions"
Diffstat (limited to 'native/src/correction.cpp')
-rw-r--r--native/src/correction.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/native/src/correction.cpp b/native/src/correction.cpp
index d5bfed017..9a7e5f35d 100644
--- a/native/src/correction.cpp
+++ b/native/src/correction.cpp
@@ -62,7 +62,8 @@ void Correction::initCorrectionState(
}
void Correction::setCorrectionParams(const int skipPos, const int excessivePos,
- const int transposedPos, const int spaceProximityPos, const int missingSpacePos) {
+ const int transposedPos, const int spaceProximityPos, const int missingSpacePos,
+ const bool useFullEditDistance) {
// TODO: remove
mTransposedPos = transposedPos;
mExcessivePos = excessivePos;
@@ -74,6 +75,7 @@ void Correction::setCorrectionParams(const int skipPos, const int excessivePos,
mSpaceProximityPos = spaceProximityPos;
mMissingSpacePos = missingSpacePos;
+ mUseFullEditDistance = useFullEditDistance;
}
void Correction::checkState() {
@@ -439,7 +441,7 @@ inline static void multiplyIntCapped(const int multiplier, int *base) {
}
inline static int powerIntCapped(const int base, const int n) {
- if (n == 0) return 1;
+ if (n <= 0) return 1;
if (base == 2) {
return n < 31 ? 1 << n : S_INT_MAX;
} else {
@@ -529,6 +531,8 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
const int excessiveCount = correction->mExcessiveCount + correction->mTransposedCount % 2;
const int proximityMatchedCount = correction->mProximityCount;
const bool lastCharExceeded = correction->mLastCharExceeded;
+ const bool useFullEditDistance = correction->mUseFullEditDistance;
+ const int outputLength = outputIndex + 1;
if (skippedCount >= inputLength || inputLength == 0) {
return -1;
}
@@ -682,6 +686,12 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
multiplyIntCapped(fullWordMultiplier, &finalFreq);
}
+ if (useFullEditDistance && outputLength > inputLength + 1) {
+ const int diff = outputLength - inputLength - 1;
+ const int divider = diff < 31 ? 1 << diff : S_INT_MAX;
+ finalFreq = divider > finalFreq ? 1 : finalFreq / divider;
+ }
+
if (DEBUG_DICT_FULL) {
LOGI("calc: %d, %d", outputIndex, sameLength);
}