diff options
author | 2013-04-10 19:35:32 -0700 | |
---|---|---|
committer | 2013-04-10 19:35:32 -0700 | |
commit | e90df24386ca22689abccaacf70a087912c00343 (patch) | |
tree | fec49353f47879450ebab7ca30230d2335b07c16 /native/jni/src/correction.cpp | |
parent | da90ffe048850df35a1a8d159d6b50eb2c14bda6 (diff) | |
parent | 481412bb44d6c3b971b28b490babbcbad4283003 (diff) | |
download | latinime-e90df24386ca22689abccaacf70a087912c00343.tar.gz latinime-e90df24386ca22689abccaacf70a087912c00343.tar.xz latinime-e90df24386ca22689abccaacf70a087912c00343.zip |
am 481412bb: am f3633e9b: Merge "Add flag to turn on new suggest implementation for typing"
* commit '481412bb44d6c3b971b28b490babbcbad4283003':
Add flag to turn on new suggest implementation for typing
Diffstat (limited to 'native/jni/src/correction.cpp')
-rw-r--r-- | native/jni/src/correction.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index 671507ee0..76234f840 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -954,7 +954,13 @@ inline static int editDistanceInternal(int *editDistanceTable, const int *before // In dictionary.cpp, getSuggestion() method, -// suggestion scores are computed using the below formula. +// When USE_SUGGEST_INTERFACE_FOR_TYPING is true: +// SUGGEST_INTERFACE_OUTPUT_SCALE was multiplied to the original suggestion scores to convert +// them to integers. +// score = (int)((original score) * SUGGEST_INTERFACE_OUTPUT_SCALE) +// Undo the scaling here to recover the original score. +// normalizedScore = ((float)score) / SUGGEST_INTERFACE_OUTPUT_SCALE +// Otherwise: suggestion scores are computed using the below formula. // original score // := powf(mTypedLetterMultiplier (this is defined 2), // (the number of matched characters between typed word and suggested word)) @@ -991,16 +997,20 @@ inline static int editDistanceInternal(int *editDistanceTable, const int *before return 0.0f; } + // add a weight based on edit distance. + // distance <= max(afterLength, beforeLength) == afterLength, + // so, 0 <= distance / afterLength <= 1 + const float weight = 1.0f - static_cast<float>(distance) / static_cast<float>(afterLength); + + if (USE_SUGGEST_INTERFACE_FOR_TYPING) { + return (static_cast<float>(score) / SUGGEST_INTERFACE_OUTPUT_SCALE) * weight; + } const float maxScore = score >= S_INT_MAX ? static_cast<float>(S_INT_MAX) : static_cast<float>(MAX_INITIAL_SCORE) * powf(static_cast<float>(TYPED_LETTER_MULTIPLIER), static_cast<float>(min(beforeLength, afterLength - spaceCount))) * static_cast<float>(FULL_WORD_MULTIPLIER); - // add a weight based on edit distance. - // distance <= max(afterLength, beforeLength) == afterLength, - // so, 0 <= distance / afterLength <= 1 - const float weight = 1.0f - static_cast<float>(distance) / static_cast<float>(afterLength); return (static_cast<float>(score) / maxScore) * weight; } } // namespace latinime |