diff options
author | 2012-05-29 01:30:26 -0700 | |
---|---|---|
committer | 2012-05-29 01:30:26 -0700 | |
commit | 40ab25cab0e723f34dc2f1442f414761149b2338 (patch) | |
tree | e408921bbe0f3a20bee5d4c44c4f4ae340090bf2 /native/jni/src/unigram_dictionary.cpp | |
parent | e3864d429e699469644fa7ae867fd48e8206bd04 (diff) | |
parent | 51705efc96c1c555cf9e0f557ea8cdc1c1c97781 (diff) | |
download | latinime-40ab25cab0e723f34dc2f1442f414761149b2338.tar.gz latinime-40ab25cab0e723f34dc2f1442f414761149b2338.tar.xz latinime-40ab25cab0e723f34dc2f1442f414761149b2338.zip |
am 51705efc: Merge "Add a JNI to get the frequency" into jb-dev
* commit '51705efc96c1c555cf9e0f557ea8cdc1c1c97781':
Add a JNI to get the frequency
Diffstat (limited to 'native/jni/src/unigram_dictionary.cpp')
-rw-r--r-- | native/jni/src/unigram_dictionary.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp index 8d2f4cd73..d68265afb 100644 --- a/native/jni/src/unigram_dictionary.cpp +++ b/native/jni/src/unigram_dictionary.cpp @@ -748,8 +748,21 @@ int UnigramDictionary::getMostFrequentWordLikeInner(const uint16_t * const inWor return maxFreq; } -bool UnigramDictionary::isValidWord(const int32_t* const inWord, const int length) const { - return NOT_VALID_WORD != BinaryFormat::getTerminalPosition(DICT_ROOT, inWord, length); +int UnigramDictionary::getFrequency(const int32_t* const inWord, const int length) const { + const uint8_t* const root = DICT_ROOT; + int pos = BinaryFormat::getTerminalPosition(root, inWord, length); + if (NOT_VALID_WORD == pos) { + return NOT_A_PROBABILITY; + } + const uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); + const bool hasMultipleChars = (0 != (FLAG_HAS_MULTIPLE_CHARS & flags)); + if (hasMultipleChars) { + pos = BinaryFormat::skipOtherCharacters(root, pos); + } else { + BinaryFormat::getCharCodeAndForwardPointer(DICT_ROOT, &pos); + } + const int unigramFreq = BinaryFormat::readFrequencyWithoutMovingPointer(root, pos); + return unigramFreq; } // TODO: remove this function. |