Loading native/jni/src/correction.cpp +15 −5 Original line number Diff line number Diff line Loading @@ -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)) Loading Loading @@ -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 native/jni/src/defines.h +1 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ static inline void prof_out(void) { #define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true #define SUGGEST_MULTIPLE_WORDS true #define USE_SUGGEST_INTERFACE_FOR_TYPING true #define SUGGEST_INTERFACE_OUTPUT_SCALE 1000000.0f // The following "rate"s are used as a multiplier before dividing by 100, so they are in percent. Loading native/jni/src/dictionary.cpp +25 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "LatinIME: dictionary.cpp" #include <map> // TODO: remove #include <stdint.h> #include "bigram_dictionary.h" Loading @@ -24,6 +25,7 @@ #include "dictionary.h" #include "dic_traverse_wrapper.h" #include "gesture_suggest.h" #include "typing_suggest.h" #include "unigram_dictionary.h" namespace latinime { Loading @@ -34,13 +36,15 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust) mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))), mBigramDictionary(new BigramDictionary(mOffsetDict)), mGestureSuggest(new GestureSuggest()) { mGestureSuggest(new GestureSuggest()), mTypingSuggest(new TypingSuggest()) { } Dictionary::~Dictionary() { delete mUnigramDictionary; delete mBigramDictionary; delete mGestureSuggest; delete mTypingSuggest; } int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, Loading @@ -59,17 +63,29 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi DUMP_RESULT(outWords, frequencies); } return result; } else { if (USE_SUGGEST_INTERFACE_FOR_TYPING) { DicTraverseWrapper::initDicTraverseSession( traverseSession, this, prevWordCodePoints, prevWordLength); result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies, spaceIndices, outputTypes); if (DEBUG_DICT) { DUMP_RESULT(outWords, frequencies); } return result; } else { std::map<int, int> bigramMap; uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE]; mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints, prevWordLength, &bigramMap, bigramFilter); result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates, inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance, outWords, frequencies, outputTypes); inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance, outWords, frequencies, outputTypes); return result; } } } int Dictionary::getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords, int *frequencies, int *outputTypes) const { Loading native/jni/src/dictionary.h +1 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class Dictionary { const UnigramDictionary *mUnigramDictionary; const BigramDictionary *mBigramDictionary; SuggestInterface *mGestureSuggest; SuggestInterface *mTypingSuggest; }; } // namespace latinime #endif // LATINIME_DICTIONARY_H Loading
native/jni/src/correction.cpp +15 −5 Original line number Diff line number Diff line Loading @@ -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)) Loading Loading @@ -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
native/jni/src/defines.h +1 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ static inline void prof_out(void) { #define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true #define SUGGEST_MULTIPLE_WORDS true #define USE_SUGGEST_INTERFACE_FOR_TYPING true #define SUGGEST_INTERFACE_OUTPUT_SCALE 1000000.0f // The following "rate"s are used as a multiplier before dividing by 100, so they are in percent. Loading
native/jni/src/dictionary.cpp +25 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "LatinIME: dictionary.cpp" #include <map> // TODO: remove #include <stdint.h> #include "bigram_dictionary.h" Loading @@ -24,6 +25,7 @@ #include "dictionary.h" #include "dic_traverse_wrapper.h" #include "gesture_suggest.h" #include "typing_suggest.h" #include "unigram_dictionary.h" namespace latinime { Loading @@ -34,13 +36,15 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust) mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust), mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))), mBigramDictionary(new BigramDictionary(mOffsetDict)), mGestureSuggest(new GestureSuggest()) { mGestureSuggest(new GestureSuggest()), mTypingSuggest(new TypingSuggest()) { } Dictionary::~Dictionary() { delete mUnigramDictionary; delete mBigramDictionary; delete mGestureSuggest; delete mTypingSuggest; } int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, Loading @@ -59,17 +63,29 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi DUMP_RESULT(outWords, frequencies); } return result; } else { if (USE_SUGGEST_INTERFACE_FOR_TYPING) { DicTraverseWrapper::initDicTraverseSession( traverseSession, this, prevWordCodePoints, prevWordLength); result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies, spaceIndices, outputTypes); if (DEBUG_DICT) { DUMP_RESULT(outWords, frequencies); } return result; } else { std::map<int, int> bigramMap; uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE]; mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints, prevWordLength, &bigramMap, bigramFilter); result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates, inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance, outWords, frequencies, outputTypes); inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance, outWords, frequencies, outputTypes); return result; } } } int Dictionary::getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords, int *frequencies, int *outputTypes) const { Loading
native/jni/src/dictionary.h +1 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class Dictionary { const UnigramDictionary *mUnigramDictionary; const BigramDictionary *mBigramDictionary; SuggestInterface *mGestureSuggest; SuggestInterface *mTypingSuggest; }; } // namespace latinime #endif // LATINIME_DICTIONARY_H