aboutsummaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-07-25 23:46:03 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-25 23:46:03 -0700
commit537ad5a56f791e74d485eb19463f00de4a1247e3 (patch)
tree4c51701f769da06ce5de5c871610b1036242469c /native/src
parent3d7c4eace8e3dc96e1326c1ed00c8ae7ef29e674 (diff)
parent848b69a5f904d7c897f6f617c8ae4585c9b90998 (diff)
downloadlatinime-537ad5a56f791e74d485eb19463f00de4a1247e3.tar.gz
latinime-537ad5a56f791e74d485eb19463f00de4a1247e3.tar.xz
latinime-537ad5a56f791e74d485eb19463f00de4a1247e3.zip
Merge "Some refactoring"
Diffstat (limited to 'native/src')
-rw-r--r--native/src/unigram_dictionary.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp
index 64d41f32e..3cfed6f46 100644
--- a/native/src/unigram_dictionary.cpp
+++ b/native/src/unigram_dictionary.cpp
@@ -1055,9 +1055,9 @@ int UnigramDictionary::getMostFrequentWordLikeInner(const uint16_t * const inWor
return maxFreq;
}
-// This function gets the frequency of the exact matching word in the dictionary.
-// If no match is found, it returns NOT_VALID_WORD.
-static inline int getFrequency(const uint8_t* const root, const uint16_t* const inWord,
+// This function gets the byte position of the last chargroup of the exact matching word in the
+// dictionary. If no match is found, it returns NOT_VALID_WORD.
+static inline int getTerminalPosition(const uint8_t* const root, const uint16_t* const inWord,
const int length) {
int pos = 0;
int wordPos = 0;
@@ -1072,6 +1072,7 @@ static inline int getFrequency(const uint8_t* const root, const uint16_t* const
// If there are no more character groups in this node, it means we could not
// find a matching character for this depth, therefore there is no match.
if (0 >= charGroupCount) return NOT_VALID_WORD;
+ const int charGroupPos = pos;
const uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(root, &pos);
int32_t character = BinaryFormat::getCharCodeAndForwardPointer(root, &pos);
if (character == wChar) {
@@ -1099,7 +1100,7 @@ static inline int getFrequency(const uint8_t* const root, const uint16_t* const
++wordPos;
if (UnigramDictionary::FLAG_IS_TERMINAL & flags) {
if (wordPos == length) {
- return BinaryFormat::readFrequencyWithoutMovingPointer(root, pos);
+ return charGroupPos;
}
pos = BinaryFormat::skipFrequency(UnigramDictionary::FLAG_IS_TERMINAL, pos);
}
@@ -1126,7 +1127,7 @@ static inline int getFrequency(const uint8_t* const root, const uint16_t* const
}
bool UnigramDictionary::isValidWord(const uint16_t* const inWord, const int length) const {
- return NOT_VALID_WORD != getFrequency(DICT_ROOT, inWord, length);
+ return NOT_VALID_WORD != getTerminalPosition(DICT_ROOT, inWord, length);
}
int UnigramDictionary::getBigrams(unsigned short *word, int length, int *codes, int codesSize,