Add words priority queue pool
Change-Id: I152df7b876a1756b69ded2ca4fb3ee26b38c971fmain
parent
4d355989bd
commit
a7e5a5a6b9
|
@ -202,6 +202,10 @@ static void dumpWord(const unsigned short* word, const int length) {
|
||||||
// This is only used for the size of array. Not to be used in c functions.
|
// This is only used for the size of array. Not to be used in c functions.
|
||||||
#define MAX_WORD_LENGTH_INTERNAL 48
|
#define MAX_WORD_LENGTH_INTERNAL 48
|
||||||
|
|
||||||
|
// Word limit for sub queues used in WordsPriorityQueuePool. Sub queues are temporary queues used
|
||||||
|
// for better performance.
|
||||||
|
#define SUB_QUEUE_MAX_WORDS 5
|
||||||
|
|
||||||
#define MAX_DEPTH_MULTIPLIER 3
|
#define MAX_DEPTH_MULTIPLIER 3
|
||||||
|
|
||||||
// TODO: Reduce this constant if possible; check the maximum number of umlauts in the same German
|
// TODO: Reduce this constant if possible; check the maximum number of umlauts in the same German
|
||||||
|
|
|
@ -39,7 +39,8 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier);
|
mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier);
|
||||||
mWordsPriorityQueue = new WordsPriorityQueue(maxWords, maxWordLength);
|
mWordsPriorityQueuePool = new WordsPriorityQueuePool(
|
||||||
|
maxWords, SUB_QUEUE_MAX_WORDS, maxWordLength);
|
||||||
mUnigramDictionary = new UnigramDictionary(mDict, typedLetterMultiplier, fullWordMultiplier,
|
mUnigramDictionary = new UnigramDictionary(mDict, typedLetterMultiplier, fullWordMultiplier,
|
||||||
maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
|
maxWordLength, maxWords, maxAlternatives, IS_LATEST_DICT_VERSION);
|
||||||
mBigramDictionary = new BigramDictionary(mDict, maxWordLength, maxAlternatives,
|
mBigramDictionary = new BigramDictionary(mDict, maxWordLength, maxAlternatives,
|
||||||
|
@ -48,7 +49,7 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
|
||||||
|
|
||||||
Dictionary::~Dictionary() {
|
Dictionary::~Dictionary() {
|
||||||
delete mCorrection;
|
delete mCorrection;
|
||||||
delete mWordsPriorityQueue;
|
delete mWordsPriorityQueuePool;
|
||||||
delete mUnigramDictionary;
|
delete mUnigramDictionary;
|
||||||
delete mBigramDictionary;
|
delete mBigramDictionary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info.h"
|
#include "proximity_info.h"
|
||||||
#include "unigram_dictionary.h"
|
#include "unigram_dictionary.h"
|
||||||
#include "words_priority_queue.h"
|
#include "words_priority_queue_pool.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public:
|
||||||
|
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||||
int *codes, int codesSize, int flags, unsigned short *outWords, int *frequencies) {
|
int *codes, int codesSize, int flags, unsigned short *outWords, int *frequencies) {
|
||||||
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueue,
|
return mUnigramDictionary->getSuggestions(proximityInfo, mWordsPriorityQueuePool,
|
||||||
mCorrection, xcoordinates, ycoordinates, codes,
|
mCorrection, xcoordinates, ycoordinates, codes,
|
||||||
codesSize, flags, outWords, frequencies);
|
codesSize, flags, outWords, frequencies);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ private:
|
||||||
const bool IS_LATEST_DICT_VERSION;
|
const bool IS_LATEST_DICT_VERSION;
|
||||||
UnigramDictionary *mUnigramDictionary;
|
UnigramDictionary *mUnigramDictionary;
|
||||||
BigramDictionary *mBigramDictionary;
|
BigramDictionary *mBigramDictionary;
|
||||||
WordsPriorityQueue *mWordsPriorityQueue;
|
WordsPriorityQueuePool *mWordsPriorityQueuePool;
|
||||||
Correction *mCorrection;
|
Correction *mCorrection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
||||||
const int *xcoordinates, const int *ycoordinates, const int *codesBuffer,
|
const int *xcoordinates, const int *ycoordinates, const int *codesBuffer,
|
||||||
const int codesBufferSize, const int flags, const int *codesSrc,
|
const int codesBufferSize, const int flags, const int *codesSrc,
|
||||||
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
|
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
|
||||||
WordsPriorityQueue *queue) {
|
WordsPriorityQueuePool *queuePool) {
|
||||||
|
|
||||||
if (currentDepth < MAX_UMLAUT_SEARCH_DEPTH) {
|
if (currentDepth < MAX_UMLAUT_SEARCH_DEPTH) {
|
||||||
for (int i = 0; i < codesRemain; ++i) {
|
for (int i = 0; i < codesRemain; ++i) {
|
||||||
|
@ -110,7 +110,8 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
||||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
||||||
codesBuffer, codesBufferSize, flags,
|
codesBuffer, codesBufferSize, flags,
|
||||||
codesSrc + (i + 1) * MAX_PROXIMITY_CHARS, codesRemain - i - 1,
|
codesSrc + (i + 1) * MAX_PROXIMITY_CHARS, codesRemain - i - 1,
|
||||||
currentDepth + 1, codesDest + i * MAX_PROXIMITY_CHARS, correction, queue);
|
currentDepth + 1, codesDest + i * MAX_PROXIMITY_CHARS, correction,
|
||||||
|
queuePool);
|
||||||
|
|
||||||
// Copy the second char of the digraph in place, then continue processing on
|
// Copy the second char of the digraph in place, then continue processing on
|
||||||
// the remaining part of the word.
|
// the remaining part of the word.
|
||||||
|
@ -120,7 +121,7 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
||||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
|
||||||
codesBuffer, codesBufferSize, flags,
|
codesBuffer, codesBufferSize, flags,
|
||||||
codesSrc + i * MAX_PROXIMITY_CHARS, codesRemain - i, currentDepth + 1,
|
codesSrc + i * MAX_PROXIMITY_CHARS, codesRemain - i, currentDepth + 1,
|
||||||
codesDest + i * MAX_PROXIMITY_CHARS, correction, queue);
|
codesDest + i * MAX_PROXIMITY_CHARS, correction, queuePool);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,27 +138,28 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
|
||||||
|
|
||||||
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
||||||
(codesDest - codesBuffer) / MAX_PROXIMITY_CHARS + codesRemain, flags, correction,
|
(codesDest - codesBuffer) / MAX_PROXIMITY_CHARS + codesRemain, flags, correction,
|
||||||
queue);
|
queuePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, WordsPriorityQueue *queue,
|
int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
||||||
Correction *correction, const int *xcoordinates, const int *ycoordinates, const int *codes,
|
WordsPriorityQueuePool *queuePool, Correction *correction, const int *xcoordinates,
|
||||||
const int codesSize, const int flags, unsigned short *outWords, int *frequencies) {
|
const int *ycoordinates, const int *codes, const int codesSize, const int flags,
|
||||||
|
unsigned short *outWords, int *frequencies) {
|
||||||
|
|
||||||
WordsPriorityQueue* masterQueue = queue;
|
|
||||||
Correction* masterCorrection = correction;
|
Correction* masterCorrection = correction;
|
||||||
if (REQUIRES_GERMAN_UMLAUT_PROCESSING & flags)
|
if (REQUIRES_GERMAN_UMLAUT_PROCESSING & flags)
|
||||||
{ // Incrementally tune the word and try all possibilities
|
{ // Incrementally tune the word and try all possibilities
|
||||||
int codesBuffer[getCodesBufferSize(codes, codesSize, MAX_PROXIMITY_CHARS)];
|
int codesBuffer[getCodesBufferSize(codes, codesSize, MAX_PROXIMITY_CHARS)];
|
||||||
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
|
||||||
codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, masterQueue);
|
codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool);
|
||||||
} else { // Normal processing
|
} else { // Normal processing
|
||||||
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize, flags,
|
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, codesSize, flags,
|
||||||
masterCorrection, masterQueue);
|
masterCorrection, queuePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROF_START(20);
|
PROF_START(20);
|
||||||
const int suggestedWordsCount = masterQueue->outputSuggestions(frequencies, outWords);
|
const int suggestedWordsCount =
|
||||||
|
queuePool->getMasterQueue()->outputSuggestions(frequencies, outWords);
|
||||||
|
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
LOGI("Returning %d words", suggestedWordsCount);
|
LOGI("Returning %d words", suggestedWordsCount);
|
||||||
|
@ -178,11 +180,13 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, WordsPriorit
|
||||||
|
|
||||||
void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
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, WordsPriorityQueue *queue) {
|
const int inputLength, const int flags, Correction *correction,
|
||||||
|
WordsPriorityQueuePool *queuePool) {
|
||||||
|
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
|
||||||
|
|
||||||
PROF_OPEN;
|
PROF_OPEN;
|
||||||
PROF_START(0);
|
PROF_START(0);
|
||||||
initSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, inputLength, queue);
|
initSuggestions(proximityInfo, xcoordinates, ycoordinates, codes, inputLength, masterQueue);
|
||||||
if (DEBUG_DICT) assert(codesSize == inputLength);
|
if (DEBUG_DICT) assert(codesSize == inputLength);
|
||||||
|
|
||||||
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
|
const int maxDepth = min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
|
||||||
|
@ -192,7 +196,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
||||||
const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
|
const bool useFullEditDistance = USE_FULL_EDIT_DISTANCE & flags;
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
PROF_START(1);
|
PROF_START(1);
|
||||||
getSuggestionCandidates(useFullEditDistance, inputLength, correction, queue);
|
getSuggestionCandidates(useFullEditDistance, inputLength, correction, masterQueue);
|
||||||
PROF_END(1);
|
PROF_END(1);
|
||||||
|
|
||||||
PROF_START(2);
|
PROF_START(2);
|
||||||
|
@ -216,7 +220,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
|
||||||
LOGI("--- Suggest missing space characters %d", i);
|
LOGI("--- Suggest missing space characters %d", i);
|
||||||
}
|
}
|
||||||
getMissingSpaceWords(
|
getMissingSpaceWords(
|
||||||
inputLength, i, proximityInfo, correction, useFullEditDistance, queue);
|
inputLength, i, proximityInfo, correction, useFullEditDistance, queuePool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PROF_END(5);
|
PROF_END(5);
|
||||||
|
@ -235,8 +239,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(
|
getMistypedSpaceWords(inputLength, i, proximityInfo, correction,
|
||||||
inputLength, i, proximityInfo, correction, useFullEditDistance, queue);
|
useFullEditDistance, queuePool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,20 +297,20 @@ void UnigramDictionary::getSuggestionCandidates(const bool useFullEditDistance,
|
||||||
|
|
||||||
void UnigramDictionary::getMissingSpaceWords(
|
void UnigramDictionary::getMissingSpaceWords(
|
||||||
const int inputLength, const int missingSpacePos, ProximityInfo *proximityInfo,
|
const int inputLength, const int missingSpacePos, ProximityInfo *proximityInfo,
|
||||||
Correction *correction, const bool useFullEditDistance, WordsPriorityQueue *queue) {
|
Correction *correction, const bool useFullEditDistance, 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, queue);
|
getSplitTwoWordsSuggestion(inputLength, proximityInfo, correction, queuePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnigramDictionary::getMistypedSpaceWords(
|
void UnigramDictionary::getMistypedSpaceWords(
|
||||||
const int inputLength, const int spaceProximityPos, ProximityInfo *proximityInfo,
|
const int inputLength, const int spaceProximityPos, ProximityInfo *proximityInfo,
|
||||||
Correction *correction, const bool useFullEditDistance, WordsPriorityQueue *queue) {
|
Correction *correction, const bool useFullEditDistance, 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, queue);
|
getSplitTwoWordsSuggestion(inputLength, proximityInfo, correction, queuePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void UnigramDictionary::onTerminal(
|
inline void UnigramDictionary::onTerminal(
|
||||||
|
@ -321,7 +325,9 @@ inline void UnigramDictionary::onTerminal(
|
||||||
|
|
||||||
void UnigramDictionary::getSplitTwoWordsSuggestion(
|
void UnigramDictionary::getSplitTwoWordsSuggestion(
|
||||||
const int inputLength, ProximityInfo *proximityInfo, Correction *correction,
|
const int inputLength, ProximityInfo *proximityInfo, Correction *correction,
|
||||||
WordsPriorityQueue *queue) {
|
WordsPriorityQueuePool *queuePool) {
|
||||||
|
WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
|
||||||
|
|
||||||
const int spaceProximityPos = correction->getSpaceProximityPos();
|
const int spaceProximityPos = correction->getSpaceProximityPos();
|
||||||
const int missingSpacePos = correction->getMissingSpacePos();
|
const int missingSpacePos = correction->getMissingSpacePos();
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
|
@ -373,7 +379,7 @@ void UnigramDictionary::getSplitTwoWordsSuggestion(
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
LOGI("Split two words: %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength);
|
LOGI("Split two words: %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength);
|
||||||
}
|
}
|
||||||
addWord(word, newWordLength, pairFreq, queue);
|
addWord(word, newWordLength, pairFreq, masterQueue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "proximity_info.h"
|
#include "proximity_info.h"
|
||||||
#include "words_priority_queue.h"
|
#include "words_priority_queue.h"
|
||||||
|
#include "words_priority_queue_pool.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ public:
|
||||||
const bool isLatestDictVersion);
|
const bool isLatestDictVersion);
|
||||||
bool isValidWord(const uint16_t* const inWord, const int length) const;
|
bool isValidWord(const uint16_t* const inWord, const int length) const;
|
||||||
int getBigramPosition(int pos, unsigned short *word, int offset, int length) const;
|
int getBigramPosition(int pos, unsigned short *word, int offset, int length) const;
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, WordsPriorityQueue *queue,
|
int getSuggestions(ProximityInfo *proximityInfo, WordsPriorityQueuePool *queuePool,
|
||||||
Correction *correction, const int *xcoordinates,
|
Correction *correction, 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);
|
||||||
|
@ -80,13 +81,13 @@ private:
|
||||||
|
|
||||||
void getWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
|
void getWordSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
|
||||||
const int *ycoordinates, const int *codes, const int inputLength,
|
const int *ycoordinates, const int *codes, const int inputLength,
|
||||||
const int flags, Correction *correction, WordsPriorityQueue *queue);
|
const int flags, Correction *correction, WordsPriorityQueuePool *queuePool);
|
||||||
bool isDigraph(const int *codes, const int i, const int codesSize) const;
|
bool isDigraph(const int *codes, const int i, const int codesSize) const;
|
||||||
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
|
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo,
|
||||||
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
|
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
|
||||||
const int codesBufferSize, const int flags, const int* codesSrc,
|
const int codesBufferSize, const int flags, const int* codesSrc,
|
||||||
const int codesRemain, const int currentDepth, int* codesDest, Correction *correction,
|
const int codesRemain, const int currentDepth, int* codesDest, Correction *correction,
|
||||||
WordsPriorityQueue* queue);
|
WordsPriorityQueuePool* queuePool);
|
||||||
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);
|
||||||
|
@ -94,13 +95,13 @@ private:
|
||||||
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 getSplitTwoWordsSuggestion(const int inputLength, ProximityInfo *proximityInfo,
|
||||||
Correction *correction, WordsPriorityQueue *queue);
|
Correction *correction, WordsPriorityQueuePool *queuePool);
|
||||||
void getMissingSpaceWords(const int inputLength, const int missingSpacePos,
|
void getMissingSpaceWords(const int inputLength, const int missingSpacePos,
|
||||||
ProximityInfo *proximityInfo, Correction *correction,
|
ProximityInfo *proximityInfo, Correction *correction,
|
||||||
const bool useFullEditDistance, WordsPriorityQueue *queue);
|
const bool useFullEditDistance, WordsPriorityQueuePool *queuePool);
|
||||||
void getMistypedSpaceWords(const int inputLength, const int spaceProximityPos,
|
void getMistypedSpaceWords(const int inputLength, const int spaceProximityPos,
|
||||||
ProximityInfo *proximityInfo, Correction *correction,
|
ProximityInfo *proximityInfo, Correction *correction,
|
||||||
const bool useFullEditDistance, WordsPriorityQueue *queue);
|
const bool useFullEditDistance, 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);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
class WordsPriorityQueue {
|
class WordsPriorityQueue {
|
||||||
private:
|
public:
|
||||||
class SuggestedWord {
|
class SuggestedWord {
|
||||||
public:
|
public:
|
||||||
int mScore;
|
int mScore;
|
||||||
|
@ -40,31 +40,6 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wordComparator {
|
|
||||||
bool operator ()(SuggestedWord * left, SuggestedWord * right) {
|
|
||||||
return left->mScore > right->mScore;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SuggestedWord* getFreeSuggestedWord(int score, unsigned short* word,
|
|
||||||
int wordLength) {
|
|
||||||
for (unsigned int i = 0; i < MAX_WORD_LENGTH; ++i) {
|
|
||||||
if (!mSuggestedWords[i].mUsed) {
|
|
||||||
mSuggestedWords[i].setParams(score, word, wordLength);
|
|
||||||
return &mSuggestedWords[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef std::priority_queue<SuggestedWord*, std::vector<SuggestedWord*>,
|
|
||||||
wordComparator> Suggestions;
|
|
||||||
Suggestions mSuggestions;
|
|
||||||
const unsigned int MAX_WORDS;
|
|
||||||
const unsigned int MAX_WORD_LENGTH;
|
|
||||||
SuggestedWord* mSuggestedWords;
|
|
||||||
|
|
||||||
public:
|
|
||||||
WordsPriorityQueue(int maxWords, int maxWordLength) :
|
WordsPriorityQueue(int maxWords, int maxWordLength) :
|
||||||
MAX_WORDS((unsigned int) maxWords), MAX_WORD_LENGTH(
|
MAX_WORDS((unsigned int) maxWords), MAX_WORD_LENGTH(
|
||||||
(unsigned int) maxWordLength) {
|
(unsigned int) maxWordLength) {
|
||||||
|
@ -105,6 +80,13 @@ public:
|
||||||
mSuggestions.push(sw);
|
mSuggestions.push(sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SuggestedWord* topAndPop() {
|
||||||
|
if (mSuggestions.empty()) return 0;
|
||||||
|
SuggestedWord* sw = mSuggestions.top();
|
||||||
|
mSuggestions.pop();
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
int outputSuggestions(int *frequencies, unsigned short *outputChars) {
|
int outputSuggestions(int *frequencies, unsigned short *outputChars) {
|
||||||
const unsigned int size = min(MAX_WORDS, mSuggestions.size());
|
const unsigned int size = min(MAX_WORDS, mSuggestions.size());
|
||||||
int index = size - 1;
|
int index = size - 1;
|
||||||
|
@ -140,6 +122,30 @@ public:
|
||||||
mSuggestions.pop();
|
mSuggestions.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
struct wordComparator {
|
||||||
|
bool operator ()(SuggestedWord * left, SuggestedWord * right) {
|
||||||
|
return left->mScore > right->mScore;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SuggestedWord* getFreeSuggestedWord(int score, unsigned short* word,
|
||||||
|
int wordLength) {
|
||||||
|
for (unsigned int i = 0; i < MAX_WORD_LENGTH; ++i) {
|
||||||
|
if (!mSuggestedWords[i].mUsed) {
|
||||||
|
mSuggestedWords[i].setParams(score, word, wordLength);
|
||||||
|
return &mSuggestedWords[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef std::priority_queue<SuggestedWord*, std::vector<SuggestedWord*>,
|
||||||
|
wordComparator> Suggestions;
|
||||||
|
Suggestions mSuggestions;
|
||||||
|
const unsigned int MAX_WORDS;
|
||||||
|
const unsigned int MAX_WORD_LENGTH;
|
||||||
|
SuggestedWord* mSuggestedWords;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LATINIME_WORDS_PRIORITY_QUEUE_POOL_H
|
||||||
|
#define LATINIME_WORDS_PRIORITY_QUEUE_POOL_H
|
||||||
|
|
||||||
|
#include "words_priority_queue.h"
|
||||||
|
|
||||||
|
namespace latinime {
|
||||||
|
|
||||||
|
class WordsPriorityQueuePool {
|
||||||
|
public:
|
||||||
|
WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) {
|
||||||
|
mMasterQueue = new WordsPriorityQueue(mainQueueMaxWords, maxWordLength);
|
||||||
|
mSubQueue1 = new WordsPriorityQueue(subQueueMaxWords, maxWordLength);
|
||||||
|
mSubQueue2 = new WordsPriorityQueue(subQueueMaxWords, maxWordLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
~WordsPriorityQueuePool() {
|
||||||
|
delete mMasterQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
WordsPriorityQueue* getMasterQueue() {
|
||||||
|
return mMasterQueue;
|
||||||
|
}
|
||||||
|
// TODO: Come up with more generic pool
|
||||||
|
WordsPriorityQueue* getSubQueue1() {
|
||||||
|
return mSubQueue1;
|
||||||
|
}
|
||||||
|
WordsPriorityQueue* getSubQueue2() {
|
||||||
|
return mSubQueue2;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
WordsPriorityQueue *mMasterQueue;
|
||||||
|
WordsPriorityQueue *mSubQueue1;
|
||||||
|
WordsPriorityQueue *mSubQueue2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LATINIME_WORDS_PRIORITY_QUEUE_POOL_H
|
Loading…
Reference in New Issue