am d3bf7ac1: Merge "Prepare for proximity + two words suggestion"

* commit 'd3bf7ac12fc4680dbed15ad51caf7165fc015241':
  Prepare for proximity + two words suggestion
main
satok 2011-12-16 01:46:03 -08:00 committed by Android Git Automerger
commit a53762035b
4 changed files with 66 additions and 35 deletions

View File

@ -100,9 +100,17 @@ inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y)
} }
bool ProximityInfo::hasSpaceProximity(const int x, const int y) const { bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
if (x < 0 || y < 0) {
if (DEBUG_DICT) {
LOGI("HasSpaceProximity: Illegal coordinates (%d, %d)", x, y);
assert(true);
}
return false;
}
const int startIndex = getStartIndexFromCoordinates(x, y); const int startIndex = getStartIndexFromCoordinates(x, y);
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
LOGI("hasSpaceProximity: index %d", startIndex); LOGI("hasSpaceProximity: index %d, %d, %d", startIndex, x, y);
} }
for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {

View File

@ -182,21 +182,16 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codes, const int *xcoordinates, const int *ycoordinates, const int *codes,
const int inputLength, const int flags, Correction *correction, const int inputLength, const int flags, Correction *correction,
WordsPriorityQueuePool *queuePool) { WordsPriorityQueuePool *queuePool) {
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
PROF_OPEN; PROF_OPEN;
PROF_START(0); PROF_START(0);
initSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, inputLength, masterQueue); // Note: This line is intentionally left blank
if (DEBUG_DICT) assert(codesSize == inputLength);
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
correction->initCorrection(proximityInfo, inputLength, maxDepth);
PROF_END(0); PROF_END(0);
const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
// TODO: remove
PROF_START(1); PROF_START(1);
getSuggestionCandidates(useFullEditDistance, inputLength, correction, masterQueue); const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
getOneWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, useFullEditDistance,
inputLength, correction, queuePool);
PROF_END(1); PROF_END(1);
PROF_START(2); PROF_START(2);
@ -219,8 +214,8 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("--- Suggest missing space characters %d", i); LOGI("--- Suggest missing space characters %d", i);
} }
getMissingSpaceWords( getMissingSpaceWords(proximityInfo, xcoordinates, ycoordinates, codes,
inputLength, i, proximityInfo, correction, useFullEditDistance, queuePool); useFullEditDistance, inputLength, i, correction, queuePool);
} }
} }
PROF_END(5); PROF_END(5);
@ -239,8 +234,8 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
i, x, y, proximityInfo->hasSpaceProximity(x, y)); i, x, y, proximityInfo->hasSpaceProximity(x, y));
} }
if (proximityInfo->hasSpaceProximity(x, y)) { if (proximityInfo->hasSpaceProximity(x, y)) {
getMistypedSpaceWords(inputLength, i, proximityInfo, correction, getMistypedSpaceWords(proximityInfo, xcoordinates, ycoordinates, codes,
useFullEditDistance, queuePool); useFullEditDistance, inputLength, i, correction, queuePool);
} }
} }
} }
@ -260,6 +255,18 @@ void UnigramDictionary::initSuggestions(ProximityInfo *proximityInfo, const int
static const char QUOTE = '\''; static const char QUOTE = '\'';
static const char SPACE = ' '; static const char SPACE = ' ';
void UnigramDictionary::getOneWordSuggestions(ProximityInfo *proximityInfo,
const int *xcoordinates, const int *ycoordinates, const int *codes,
const bool useFullEditDistance, const int inputLength, Correction *correction,
WordsPriorityQueuePool *queuePool) {
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
initSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, inputLength, masterQueue);
if (DEBUG_DICT) assert(codesSize == inputLength);
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
correction->initCorrection(proximityInfo, inputLength, maxDepth);
getSuggestionCandidates(useFullEditDistance, inputLength, correction, masterQueue);
}
void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance, void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance,
const int inputLength, Correction *correction, WordsPriorityQueue *queue) { const int inputLength, Correction *correction, WordsPriorityQueue *queue) {
// TODO: Remove setCorrectionParams // TODO: Remove setCorrectionParams
@ -295,22 +302,28 @@ void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance,
} }
} }
void UnigramDictionary::getMissingSpaceWords( void UnigramDictionary::getMissingSpaceWords(ProximityInfo *proximityInfo, const int *xcoordinates,
const int inputLength, const int missingSpacePos, ProximityInfo *proximityInfo, const int *ycoordinates, const int *codes, const bool useFullEditDistance,
Correction *correction, const bool useFullEditDistance, WordsPriorityQueuePool *queuePool) { const int inputLength, const int missingSpacePos, Correction *correction,
WordsPriorityQueuePool* queuePool) {
correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */, correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */,
-1 /* transposedPos */, -1 /* spaceProximityPos */, missingSpacePos, -1 /* transposedPos */, -1 /* spaceProximityPos */, missingSpacePos,
useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS); useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS);
getSplitTwoWordsSuggestion(inputLength, proximityInfo, correction, queuePool); getSplitTwoWordsSuggestions(proximityInfo, xcoordinates, ycoordinates, codes,
useFullEditDistance, inputLength, missingSpacePos, -1/* spaceProximityPos */,
correction, queuePool);
} }
void UnigramDictionary::getMistypedSpaceWords( void UnigramDictionary::getMistypedSpaceWords(ProximityInfo *proximityInfo, const int *xcoordinates,
const int inputLength, const int spaceProximityPos, ProximityInfo *proximityInfo, const int *ycoordinates, const int *codes, const bool useFullEditDistance,
Correction *correction, const bool useFullEditDistance, WordsPriorityQueuePool *queuePool) { const int inputLength, const int spaceProximityPos, Correction *correction,
WordsPriorityQueuePool* queuePool) {
correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */, correction->setCorrectionParams(-1 /* skipPos */, -1 /* excessivePos */,
-1 /* transposedPos */, spaceProximityPos, -1 /* missingSpacePos */, -1 /* transposedPos */, spaceProximityPos, -1 /* missingSpacePos */,
useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS); useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS);
getSplitTwoWordsSuggestion(inputLength, proximityInfo, correction, queuePool); getSplitTwoWordsSuggestions(proximityInfo, xcoordinates, ycoordinates, codes,
useFullEditDistance, inputLength, -1 /* missingSpacePos */, spaceProximityPos,
correction, queuePool);
} }
inline void UnigramDictionary::onTerminal( inline void UnigramDictionary::onTerminal(
@ -323,13 +336,12 @@ inline void UnigramDictionary::onTerminal(
} }
} }
void UnigramDictionary::getSplitTwoWordsSuggestion( void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo,
const int inputLength, ProximityInfo *proximityInfo, Correction *correction, const int *xcoordinates, const int *ycoordinates, const int *codes,
WordsPriorityQueuePool *queuePool) { const bool useFullEditDistance, const int inputLength, const int missingSpacePos,
const int spaceProximityPos, Correction *correction, WordsPriorityQueuePool* queuePool) {
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue(); WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
const int spaceProximityPos = correction->getSpaceProximityPos();
const int missingSpacePos = correction->getMissingSpacePos();
if (DEBUG_DICT) { if (DEBUG_DICT) {
int inputCount = 0; int inputCount = 0;
if (spaceProximityPos >= 0) ++inputCount; if (spaceProximityPos >= 0) ++inputCount;

View File

@ -91,17 +91,24 @@ private:
void initSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates, void initSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int codesSize, const int *ycoordinates, const int *codes, const int codesSize,
WordsPriorityQueue *queue); WordsPriorityQueue *queue);
void getOneWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const bool useFullEditDistance,
const int inputLength, Correction *correction, WordsPriorityQueuePool* queuePool);
void getSuggestionCandidates( void getSuggestionCandidates(
const bool useFullEditDistance, const int inputLength, Correction *correction, const bool useFullEditDistance, const int inputLength, Correction *correction,
WordsPriorityQueue* queue); WordsPriorityQueue* queue);
void getSplitTwoWordsSuggestion(const int inputLength, ProximityInfo *proximityInfo, void getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo,
Correction *correction, WordsPriorityQueuePool *queuePool); const int *xcoordinates, const int *ycoordinates, const int *codes,
void getMissingSpaceWords(const int inputLength, const int missingSpacePos, const bool useFullEditDistance, const int inputLength, const int spaceProximityPos,
ProximityInfo *proximityInfo, Correction *correction, const int missingSpacePos, Correction *correction, WordsPriorityQueuePool* queuePool);
const bool useFullEditDistance, WordsPriorityQueuePool *queuePool); void getMissingSpaceWords(ProximityInfo *proximityInfo, const int *xcoordinates,
void getMistypedSpaceWords(const int inputLength, const int spaceProximityPos, const int *ycoordinates, const int *codes, const bool useFullEditDistance,
ProximityInfo *proximityInfo, Correction *correction, const int inputLength, const int missingSpacePos, Correction *correction,
const bool useFullEditDistance, WordsPriorityQueuePool *queuePool); WordsPriorityQueuePool* queuePool);
void getMistypedSpaceWords(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const bool useFullEditDistance,
const int inputLength, const int spaceProximityPos, Correction *correction,
WordsPriorityQueuePool* queuePool);
void onTerminal(const int freq, Correction *correction, WordsPriorityQueue *queue); void onTerminal(const int freq, Correction *correction, WordsPriorityQueue *queue);
bool needsToSkipCurrentNode(const unsigned short c, bool needsToSkipCurrentNode(const unsigned short c,
const int inputIndex, const int skipPos, const int depth); const int inputIndex, const int skipPos, const int depth);

View File

@ -111,6 +111,10 @@ public:
return size; return size;
} }
int size() {
return mSuggestions.size();
}
void clear() { void clear() {
while (!mSuggestions.empty()) { while (!mSuggestions.empty()) {
SuggestedWord* sw = mSuggestions.top(); SuggestedWord* sw = mSuggestions.top();