From 980d6b6fef34e8716feb405aa8902d9f7fd37195 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 30 Jun 2011 17:02:23 +0900 Subject: [PATCH] Internal cleanup. Function renaming, useless function supressing, fix comments Change-Id: I148acbaf367cd556a85b89016676b46cc971af81 --- native/src/unigram_dictionary.cpp | 30 ++++++++++++------------------ native/src/unigram_dictionary.h | 5 +++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp index e3296f12a..d01f9c024 100644 --- a/native/src/unigram_dictionary.cpp +++ b/native/src/unigram_dictionary.cpp @@ -153,6 +153,13 @@ int UnigramDictionary::getSuggestions(const ProximityInfo *proximityInfo, const if (DEBUG_DICT) { LOGI("Returning %d words", suggestedWordsCount); + /// Print the returned words + for (int j = 0; j < suggestedWordsCount; ++j) { + short unsigned int* w = mOutputChars + j * MAX_WORD_LENGTH; + char s[MAX_WORD_LENGTH]; + for (int i = 0; i <= MAX_WORD_LENGTH; i++) s[i] = w[i]; + LOGI("%s %i", s, mFrequencies[j]); + } LOGI("Next letters: "); for (int k = 0; k < NEXT_LETTERS_SIZE; k++) { if (mNextLettersFrequency[k] > 0) { @@ -322,16 +329,6 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency) return false; } -inline void UnigramDictionary::addWordAlternatesSpellings(const uint8_t* const root, int pos, - int depth, int finalFreq) { - // TODO: actually add alternates when the format supports it. -} - -static inline bool hasAlternateSpellings(uint8_t flags) { - // TODO: when the format supports it, return the actual value. - return false; -} - static inline unsigned short toBaseLowerCase(unsigned short c) { if (c < sizeof(BASE_CHARS) / sizeof(BASE_CHARS[0])) { c = BASE_CHARS[c]; @@ -372,7 +369,7 @@ void UnigramDictionary::getSuggestionCandidates(const int skipPos, assert(missingPos < mInputLength); } int rootPosition = ROOT_POS; - // Get the number of child of root, then increment the position + // Get the number of children of root, then increment the position int childCount = Dictionary::getCount(DICT_ROOT, &rootPosition); int depth = 0; @@ -657,22 +654,19 @@ inline UnigramDictionary::ProximityType UnigramDictionary::getMatchedProximityId } inline void UnigramDictionary::onTerminal(unsigned short int* word, const int depth, - const uint8_t* const root, const uint8_t flags, int pos, + const uint8_t* const root, const uint8_t flags, const int pos, const int inputIndex, const int matchWeight, const int skipPos, const int excessivePos, const int transposedPos, const int freq, const bool sameLength, int* nextLetters, const int nextLettersSize) { const bool isSameAsTyped = sameLength ? sameAsTyped(word, depth + 1) : false; - const bool hasAlternates = hasAlternateSpellings(flags); - if (isSameAsTyped && !hasAlternates) return; + if (isSameAsTyped) return; if (depth >= MIN_SUGGEST_DEPTH) { const int finalFreq = calculateFinalFreq(inputIndex, depth, matchWeight, skipPos, excessivePos, transposedPos, freq, sameLength); if (!isSameAsTyped) addWord(word, depth + 1, finalFreq); - if (hasAlternates) - addWordAlternatesSpellings(DICT_ROOT, pos, flags, finalFreq); } if (sameLength && depth >= mInputLength && skipPos < 0) { @@ -725,8 +719,8 @@ void UnigramDictionary::getWordsRec(const int childrenCount, const int pos, cons } } -inline int UnigramDictionary::getBestWordFreq(const int startInputIndex, const int inputLength, - unsigned short *word) { +inline int UnigramDictionary::getMostFrequentWordLike(const int startInputIndex, + const int inputLength, unsigned short *word) { int pos = ROOT_POS; int count = Dictionary::getCount(DICT_ROOT, &pos); int maxFreq = 0; diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h index 56690feda..7183b208e 100644 --- a/native/src/unigram_dictionary.h +++ b/native/src/unigram_dictionary.h @@ -80,7 +80,7 @@ private: const int excessivePos, const int transposedPos, const int freq, const bool sameLength) const; void onTerminal(unsigned short int* word, const int depth, - const uint8_t* const root, const uint8_t flags, int pos, + const uint8_t* const root, const uint8_t flags, const int pos, const int inputIndex, const int matchWeight, const int skipPos, const int excessivePos, const int transposedPos, const int freq, const bool sameLength, int *nextLetters, const int nextLettersSize); @@ -95,7 +95,8 @@ private: int *nextLetters, const int nextLettersSize, int *newCount, int *newChildPosition, bool *newTraverseAllNodes, int *newSnr, int*newInputIndex, int *newDiffs, int *nextSiblingPosition, int *nextOutputIndex); - int getBestWordFreq(const int startInputIndex, const int inputLength, unsigned short *word); + int getMostFrequentWordLike(const int startInputIndex, const int inputLength, + unsigned short *word); // Process a node by considering missing space bool processCurrentNodeForExactMatch(const int firstChildPos, const int startInputIndex, const int depth, unsigned short *word,