Internal cleanup.

Function renaming, useless function supressing, fix comments

Change-Id: I148acbaf367cd556a85b89016676b46cc971af81
main
Jean Chalard 2011-06-30 17:02:23 +09:00
parent 5cceebc728
commit 980d6b6fef
2 changed files with 15 additions and 20 deletions

View File

@ -153,6 +153,13 @@ int UnigramDictionary::getSuggestions(const ProximityInfo *proximityInfo, const
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Returning %d words", suggestedWordsCount); 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: "); LOGI("Next letters: ");
for (int k = 0; k < NEXT_LETTERS_SIZE; k++) { for (int k = 0; k < NEXT_LETTERS_SIZE; k++) {
if (mNextLettersFrequency[k] > 0) { if (mNextLettersFrequency[k] > 0) {
@ -322,16 +329,6 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency)
return false; 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) { static inline unsigned short toBaseLowerCase(unsigned short c) {
if (c < sizeof(BASE_CHARS) / sizeof(BASE_CHARS[0])) { if (c < sizeof(BASE_CHARS) / sizeof(BASE_CHARS[0])) {
c = BASE_CHARS[c]; c = BASE_CHARS[c];
@ -372,7 +369,7 @@ void UnigramDictionary::getSuggestionCandidates(const int skipPos,
assert(missingPos < mInputLength); assert(missingPos < mInputLength);
} }
int rootPosition = ROOT_POS; 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 childCount = Dictionary::getCount(DICT_ROOT, &rootPosition);
int depth = 0; int depth = 0;
@ -657,22 +654,19 @@ inline UnigramDictionary::ProximityType UnigramDictionary::getMatchedProximityId
} }
inline void UnigramDictionary::onTerminal(unsigned short int* word, const int depth, 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 inputIndex, const int matchWeight, const int skipPos,
const int excessivePos, const int transposedPos, const int freq, const bool sameLength, const int excessivePos, const int transposedPos, const int freq, const bool sameLength,
int* nextLetters, const int nextLettersSize) { int* nextLetters, const int nextLettersSize) {
const bool isSameAsTyped = sameLength ? sameAsTyped(word, depth + 1) : false; const bool isSameAsTyped = sameLength ? sameAsTyped(word, depth + 1) : false;
const bool hasAlternates = hasAlternateSpellings(flags); if (isSameAsTyped) return;
if (isSameAsTyped && !hasAlternates) return;
if (depth >= MIN_SUGGEST_DEPTH) { if (depth >= MIN_SUGGEST_DEPTH) {
const int finalFreq = calculateFinalFreq(inputIndex, depth, matchWeight, skipPos, const int finalFreq = calculateFinalFreq(inputIndex, depth, matchWeight, skipPos,
excessivePos, transposedPos, freq, sameLength); excessivePos, transposedPos, freq, sameLength);
if (!isSameAsTyped) if (!isSameAsTyped)
addWord(word, depth + 1, finalFreq); addWord(word, depth + 1, finalFreq);
if (hasAlternates)
addWordAlternatesSpellings(DICT_ROOT, pos, flags, finalFreq);
} }
if (sameLength && depth >= mInputLength && skipPos < 0) { 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, inline int UnigramDictionary::getMostFrequentWordLike(const int startInputIndex,
unsigned short *word) { const int inputLength, unsigned short *word) {
int pos = ROOT_POS; int pos = ROOT_POS;
int count = Dictionary::getCount(DICT_ROOT, &pos); int count = Dictionary::getCount(DICT_ROOT, &pos);
int maxFreq = 0; int maxFreq = 0;

View File

@ -80,7 +80,7 @@ private:
const int excessivePos, const int transposedPos, const int freq, const int excessivePos, const int transposedPos, const int freq,
const bool sameLength) const; const bool sameLength) const;
void onTerminal(unsigned short int* word, const int depth, 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 inputIndex, const int matchWeight, const int skipPos,
const int excessivePos, const int transposedPos, const int freq, const bool sameLength, const int excessivePos, const int transposedPos, const int freq, const bool sameLength,
int *nextLetters, const int nextLettersSize); int *nextLetters, const int nextLettersSize);
@ -95,7 +95,8 @@ private:
int *nextLetters, const int nextLettersSize, int *newCount, int *newChildPosition, int *nextLetters, const int nextLettersSize, int *newCount, int *newChildPosition,
bool *newTraverseAllNodes, int *newSnr, int*newInputIndex, int *newDiffs, bool *newTraverseAllNodes, int *newSnr, int*newInputIndex, int *newDiffs,
int *nextSiblingPosition, int *nextOutputIndex); 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 // Process a node by considering missing space
bool processCurrentNodeForExactMatch(const int firstChildPos, bool processCurrentNodeForExactMatch(const int firstChildPos,
const int startInputIndex, const int depth, unsigned short *word, const int startInputIndex, const int depth, unsigned short *word,