Fix a bug where bigram search would never return

Bug: 4690487
Change-Id: Ie8f3f651508cc48bbb043a0b308f7e0d1524371c
main
Jean Chalard 2011-06-17 12:45:17 +09:00
parent e681d671fd
commit 581335c3fb
5 changed files with 18 additions and 6 deletions

View File

@ -111,7 +111,7 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i
mMaxBigrams = maxBigrams; mMaxBigrams = maxBigrams;
if (HAS_BIGRAM && IS_LATEST_DICT_VERSION) { if (HAS_BIGRAM && IS_LATEST_DICT_VERSION) {
int pos = mParentDictionary->isValidWord(prevWord, prevWordLength); int pos = mParentDictionary->getBigramPosition(prevWord, prevWordLength);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Pos -> %d", pos); LOGI("Pos -> %d", pos);
} }

View File

@ -57,4 +57,12 @@ bool Dictionary::isValidWord(unsigned short *word, int length) {
return mUnigramDictionary->isValidWord(word, length); return mUnigramDictionary->isValidWord(word, length);
} }
int Dictionary::getBigramPosition(unsigned short *word, int length) {
if (IS_LATEST_DICT_VERSION) {
return mUnigramDictionary->getBigramPosition(DICTIONARY_HEADER_SIZE, word, 0, length);
} else {
return mUnigramDictionary->getBigramPosition(0, word, 0, length);
}
}
} // namespace latinime } // namespace latinime

View File

@ -62,6 +62,9 @@ public:
const int pos, unsigned short *c, int *childrenPosition, const int pos, unsigned short *c, int *childrenPosition,
bool *terminal, int *freq); bool *terminal, int *freq);
// TODO: delete this
int getBigramPosition(unsigned short *word, int length);
private: private:
bool hasBigram(); bool hasBigram();

View File

@ -932,15 +932,16 @@ inline bool UnigramDictionary::processCurrentNodeForExactMatch(const int firstCh
// TODO: use uint32_t instead of unsigned short // TODO: use uint32_t instead of unsigned short
bool UnigramDictionary::isValidWord(unsigned short *word, int length) { bool UnigramDictionary::isValidWord(unsigned short *word, int length) {
if (IS_LATEST_DICT_VERSION) { if (IS_LATEST_DICT_VERSION) {
return (getFrequency(DICTIONARY_HEADER_SIZE, word, 0, length) != NOT_VALID_WORD); return (getBigramPosition(DICTIONARY_HEADER_SIZE, word, 0, length) != NOT_VALID_WORD);
} else { } else {
return (getFrequency(0, word, 0, length) != NOT_VALID_WORD); return (getBigramPosition(0, word, 0, length) != NOT_VALID_WORD);
} }
} }
// Require strict exact match. // Require strict exact match.
int UnigramDictionary::getFrequency(int pos, unsigned short *word, int offset, int length) const { int UnigramDictionary::getBigramPosition(int pos, unsigned short *word, int offset,
int length) const {
// returns address of bigram data of that word // returns address of bigram data of that word
// return -99 if not found // return -99 if not found
@ -957,7 +958,7 @@ int UnigramDictionary::getFrequency(int pos, unsigned short *word, int offset, i
} }
} else { } else {
if (childPos != 0) { if (childPos != 0) {
int t = getFrequency(childPos, word, offset + 1, length); int t = getBigramPosition(childPos, word, offset + 1, length);
if (t > 0) { if (t > 0) {
return t; return t;
} }

View File

@ -40,6 +40,7 @@ public:
int fullWordMultiplier, int maxWordLength, int maxWords, int maxProximityChars, int fullWordMultiplier, int maxWordLength, int maxWords, int maxProximityChars,
const bool isLatestDictVersion); const bool isLatestDictVersion);
bool isValidWord(unsigned short *word, int length); bool isValidWord(unsigned short *word, int length);
int getBigramPosition(int pos, unsigned short *word, int offset, int length) const;
int getSuggestions(const ProximityInfo *proximityInfo, const int *xcoordinates, int getSuggestions(const ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int codesSize, const int flags, const int *ycoordinates, const int *codes, const int codesSize, const int flags,
unsigned short *outWords, int *frequencies); unsigned short *outWords, int *frequencies);
@ -59,7 +60,6 @@ private:
void getSuggestionCandidates(const int skipPos, const int excessivePos, void getSuggestionCandidates(const int skipPos, const int excessivePos,
const int transposedPos, int *nextLetters, const int nextLettersSize, const int transposedPos, int *nextLetters, const int nextLettersSize,
const int maxDepth); const int maxDepth);
int getFrequency(int pos, unsigned short *word, int offset, int length) const;
void getVersionNumber(); void getVersionNumber();
bool checkIfDictVersionIsLatest(); bool checkIfDictVersionIsLatest();
int getAddress(int *pos); int getAddress(int *pos);