diff options
author | 2012-08-10 16:52:27 +0900 | |
---|---|---|
committer | 2012-08-13 16:35:59 +0900 | |
commit | b14fc88e482e53ba6852c8d5da5d9826c68d041f (patch) | |
tree | a2be310d3b8b9961a47ff7fca3522650fe7df30c /native/jni/src/unigram_dictionary.cpp | |
parent | 814510305c21b3081414e75e040dec4b73f6cdf3 (diff) | |
download | latinime-b14fc88e482e53ba6852c8d5da5d9826c68d041f.tar.gz latinime-b14fc88e482e53ba6852c8d5da5d9826c68d041f.tar.xz latinime-b14fc88e482e53ba6852c8d5da5d9826c68d041f.zip |
Tag the whitelisted entries in native code.
Since this is already used in Java land, this actually does
activate the whitelist path, and the code is now fully
functional. We still have to remove the old whitelist resource
and to compile the dictionary that includes the whitelist.
Bug: 6906525
Change-Id: Iacde5313e303b9ed792940efaf6bcfa4ee1317bd
Diffstat (limited to 'native/jni/src/unigram_dictionary.cpp')
-rw-r--r-- | native/jni/src/unigram_dictionary.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp index 9f7ab5362..cc6d39a29 100644 --- a/native/jni/src/unigram_dictionary.cpp +++ b/native/jni/src/unigram_dictionary.cpp @@ -391,8 +391,12 @@ inline void UnigramDictionary::onTerminal(const int probability, const int finalProbability = correction->getFinalProbability(probability, &wordPointer, &wordLength); if (finalProbability != NOT_A_PROBABILITY) { - addWord(wordPointer, wordLength, finalProbability, masterQueue, - Dictionary::KIND_CORRECTION); + if (0 != finalProbability) { + // If the probability is 0, we don't want to add this word. However we still + // want to add its shortcuts (including a possible whitelist entry) if any. + addWord(wordPointer, wordLength, finalProbability, masterQueue, + Dictionary::KIND_CORRECTION); + } const int shortcutProbability = finalProbability > 0 ? finalProbability - 1 : 0; // Please note that the shortcut candidates will be added to the master queue only. @@ -407,10 +411,21 @@ inline void UnigramDictionary::onTerminal(const int probability, // with the same score. For the moment we use -1 to make sure the shortcut will // never be in front of the word. uint16_t shortcutTarget[MAX_WORD_LENGTH_INTERNAL]; + int shortcutFrequency; const int shortcutTargetStringLength = iterator.getNextShortcutTarget( - MAX_WORD_LENGTH_INTERNAL, shortcutTarget); - addWord(shortcutTarget, shortcutTargetStringLength, shortcutProbability, - masterQueue, Dictionary::KIND_CORRECTION); + MAX_WORD_LENGTH_INTERNAL, shortcutTarget, &shortcutFrequency); + int shortcutScore; + int kind; + if (shortcutFrequency == BinaryFormat::WHITELIST_SHORTCUT_FREQUENCY + && correction->sameAsTyped()) { + shortcutScore = S_INT_MAX; + kind = Dictionary::KIND_WHITELIST; + } else { + shortcutScore = shortcutProbability; + kind = Dictionary::KIND_CORRECTION; + } + addWord(shortcutTarget, shortcutTargetStringLength, shortcutScore, + masterQueue, kind); } } } |