am 6a033505: Merge "Refactor words priority queue"

* commit '6a03350521cb1ce65dd17db8fe4a4e8cb40468cb':
  Refactor words priority queue
main
satok 2012-01-26 00:38:53 -08:00 committed by Android Git Automerger
commit 13c66f2017
4 changed files with 52 additions and 30 deletions

View File

@ -217,6 +217,7 @@ static void prof_out(void) {
#define SUB_QUEUE_MAX_WORDS 1 #define SUB_QUEUE_MAX_WORDS 1
#define SUB_QUEUE_MAX_COUNT 10 #define SUB_QUEUE_MAX_COUNT 10
#define SUB_QUEUE_MIN_WORD_LENGTH 4 #define SUB_QUEUE_MIN_WORD_LENGTH 4
#define SUB_QUEUE_MAX_WORD_INDEX 2
#define TWO_WORDS_CORRECTION_WITH_OTHER_ERROR_THRESHOLD 0.39 #define TWO_WORDS_CORRECTION_WITH_OTHER_ERROR_THRESHOLD 0.39
#define START_TWO_WORDS_CORRECTION_THRESHOLD 0.22 #define START_TWO_WORDS_CORRECTION_THRESHOLD 0.22

View File

@ -260,7 +260,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
if (DEBUG_DICT) { if (DEBUG_DICT) {
queuePool->dumpSubQueue1TopSuggestions(); queuePool->dumpSubQueue1TopSuggestions();
for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) {
WordsPriorityQueue* queue = queuePool->getSubQueue1(i); WordsPriorityQueue* queue = queuePool->getSubQueue(FIRST_WORD_INDEX, i);
if (queue->size() > 0) { if (queue->size() > 0) {
WordsPriorityQueue::SuggestedWord* sw = queue->top(); WordsPriorityQueue::SuggestedWord* sw = queue->top();
const int score = sw->mScore; const int score = sw->mScore;
@ -395,11 +395,8 @@ inline void UnigramDictionary::onTerminal(const int freq,
// or more length. // or more length.
if (inputIndex >= SUB_QUEUE_MIN_WORD_LENGTH && addToSubQueue) { if (inputIndex >= SUB_QUEUE_MIN_WORD_LENGTH && addToSubQueue) {
WordsPriorityQueue *subQueue; WordsPriorityQueue *subQueue;
if (currentWordIndex == 1) { subQueue = queuePool->getSubQueue(currentWordIndex, inputIndex);
subQueue = queuePool->getSubQueue1(inputIndex); if (!subQueue) {
} else if (currentWordIndex == 2) {
subQueue = queuePool->getSubQueue2(inputIndex);
} else {
return; return;
} }
const int finalFreq = correction->getFinalFreqForSubQueue(freq, &wordPointer, &wordLength, const int finalFreq = correction->getFinalFreqForSubQueue(freq, &wordPointer, &wordLength,
@ -408,6 +405,25 @@ inline void UnigramDictionary::onTerminal(const int freq,
} }
} }
int UnigramDictionary::getSubStringSuggestion(
ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates,
const int *codes, const bool useFullEditDistance, const Correction *correction,
WordsPriorityQueuePool* queuePool, const bool hasAutoCorrectionCandidate,
const int currentWordIndex, const int inputWordStartPos, const int inputWordLength,
const int outputWordStartPos, unsigned short* outputWord, int *outputWordLength) {
// under constructiong
// unsigned short* tempOutputWord = 0;
// int tempOutputWordLength = 0;
// int freq = getMostFrequentWordLike(
// inputWordStartPos, inputWordLength, proximityInfo, mWord);
// if (freq > 0) {
// tempOutputWordLength = inputWordLength;
// tempOutputWord = mWord;
// } else if (!hasAutoCorrectionCandidate) {
// }
return 0;
}
void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo, void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codes, const int *xcoordinates, const int *ycoordinates, const int *codes,
const bool useFullEditDistance, const int inputLength, const int missingSpacePos, const bool useFullEditDistance, const int inputLength, const int missingSpacePos,
@ -439,7 +455,8 @@ void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo
firstOutputWordLength = firstInputWordLength; firstOutputWordLength = firstInputWordLength;
firstOutputWord = mWord; firstOutputWord = mWord;
} else if (!hasAutoCorrectionCandidate) { } else if (!hasAutoCorrectionCandidate) {
WordsPriorityQueue* firstWordQueue = queuePool->getSubQueue1(firstInputWordLength); WordsPriorityQueue* firstWordQueue = queuePool->getSubQueue(
FIRST_WORD_INDEX, firstInputWordLength);
if (!firstWordQueue || firstWordQueue->size() < 1) { if (!firstWordQueue || firstWordQueue->size() < 1) {
return; return;
} }
@ -497,16 +514,17 @@ void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo
const int offset = secondInputWordStartPos; const int offset = secondInputWordStartPos;
initSuggestions(proximityInfo, &xcoordinates[offset], &ycoordinates[offset], initSuggestions(proximityInfo, &xcoordinates[offset], &ycoordinates[offset],
codes + offset * MAX_PROXIMITY_CHARS, secondInputWordLength, correction); codes + offset * MAX_PROXIMITY_CHARS, secondInputWordLength, correction);
queuePool->clearSubQueue2(); queuePool->clearSubQueue(SECOND_WORD_INDEX);
getSuggestionCandidates(useFullEditDistance, secondInputWordLength, correction, getSuggestionCandidates(useFullEditDistance, secondInputWordLength, correction,
queuePool, false, MAX_ERRORS_FOR_TWO_WORDS, SECOND_WORD_INDEX); queuePool, false, MAX_ERRORS_FOR_TWO_WORDS, SECOND_WORD_INDEX);
if (DEBUG_DICT) { if (DEBUG_DICT) {
AKLOGI("Dump second word candidates %d", secondInputWordLength); AKLOGI("Dump second word candidates %d", secondInputWordLength);
for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) {
queuePool->getSubQueue2(i)->dumpTopWord(); queuePool->getSubQueue(SECOND_WORD_INDEX, i)->dumpTopWord();
} }
} }
WordsPriorityQueue* secondWordQueue = queuePool->getSubQueue2(secondInputWordLength); WordsPriorityQueue* secondWordQueue = queuePool->getSubQueue(
SECOND_WORD_INDEX, secondInputWordLength);
if (!secondWordQueue || secondWordQueue->size() < 1) { if (!secondWordQueue || secondWordQueue->size() < 1) {
return; return;
} }

View File

@ -127,6 +127,12 @@ class UnigramDictionary {
ProximityInfo *proximityInfo, unsigned short *word); ProximityInfo *proximityInfo, unsigned short *word);
int getMostFrequentWordLikeInner(const uint16_t* const inWord, const int length, int getMostFrequentWordLikeInner(const uint16_t* const inWord, const int length,
short unsigned int *outWord); short unsigned int *outWord);
int getSubStringSuggestion(
ProximityInfo *proximityInfo, const int *xcoordinates, const int *ycoordinates,
const int *codes, const bool useFullEditDistance, const Correction *correction,
WordsPriorityQueuePool* queuePool, const bool hasAutoCorrectionCandidate,
const int currentWordIndex, const int inputWordStartPos, const int inputWordLength,
const int outputWordStartPos, unsigned short* outputWord, int *outputWordLength);
const uint8_t* const DICT_ROOT; const uint8_t* const DICT_ROOT;
const int MAX_WORD_LENGTH; const int MAX_WORD_LENGTH;

View File

@ -43,25 +43,24 @@ class WordsPriorityQueuePool {
return mMasterQueue; return mMasterQueue;
} }
// TODO: Come up with more generic pool WordsPriorityQueue* getSubQueue(const int wordIndex, const int inputWordLength) {
WordsPriorityQueue* getSubQueue1(const int id) { if (wordIndex > SUB_QUEUE_MAX_WORD_INDEX) {
if (id < 0 || id >= SUB_QUEUE_MAX_COUNT) { return 0;
}
if (inputWordLength < 0 || inputWordLength >= SUB_QUEUE_MAX_COUNT) {
if (DEBUG_WORDS_PRIORITY_QUEUE) { if (DEBUG_WORDS_PRIORITY_QUEUE) {
assert(false); assert(false);
} }
return 0; return 0;
} }
return mSubQueues1[id]; // TODO: Come up with more generic pool
} if (wordIndex == 1) {
return mSubQueues1[inputWordLength];
WordsPriorityQueue* getSubQueue2(const int id) { } else if (wordIndex == 2) {
if (id < 0 || id >= SUB_QUEUE_MAX_COUNT) { return mSubQueues2[inputWordLength];
if (DEBUG_WORDS_PRIORITY_QUEUE) { } else {
assert(false);
}
return 0; return 0;
} }
return mSubQueues2[id];
} }
inline void clearAll() { inline void clearAll() {
@ -72,15 +71,13 @@ class WordsPriorityQueuePool {
} }
} }
inline void clearSubQueue1() { inline void clearSubQueue(const int wordIndex) {
for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) {
mSubQueues1[i]->clear(); if (wordIndex == 1) {
} mSubQueues1[i]->clear();
} } else if (wordIndex == 2) {
mSubQueues2[i]->clear();
inline void clearSubQueue2() { }
for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) {
mSubQueues2[i]->clear();
} }
} }