aboutsummaryrefslogtreecommitdiffstats
path: root/native/src/words_priority_queue.h
diff options
context:
space:
mode:
authorsatok <satok@google.com>2012-01-19 02:21:18 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-01-19 02:21:18 -0800
commit2010130e4425bd18f68d9de3ec7b846d00c61e0a (patch)
treea0129f2a670cd7adc8634fa3e5cb9eb3adcffc3f /native/src/words_priority_queue.h
parent0ef9bfe5932cb1b099809b4622bf45427f0430dd (diff)
parent54af64ae921baa764d64c11c7f4f8edd6352d405 (diff)
downloadlatinime-2010130e4425bd18f68d9de3ec7b846d00c61e0a.tar.gz
latinime-2010130e4425bd18f68d9de3ec7b846d00c61e0a.tar.xz
latinime-2010130e4425bd18f68d9de3ec7b846d00c61e0a.zip
Merge "Two words error correction with other error correction for the first word"
Diffstat (limited to 'native/src/words_priority_queue.h')
-rw-r--r--native/src/words_priority_queue.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/native/src/words_priority_queue.h b/native/src/words_priority_queue.h
index 6262439b5..c85f2b9b3 100644
--- a/native/src/words_priority_queue.h
+++ b/native/src/words_priority_queue.h
@@ -47,6 +47,7 @@ class WordsPriorityQueue {
for (int i = 0; i < maxWordLength; ++i) {
mSuggestedWords[i].mUsed = false;
}
+ mHighestSuggestedWord = 0;
}
~WordsPriorityQueue() {
@@ -79,6 +80,9 @@ class WordsPriorityQueue {
DUMP_WORD(word, wordLength);
}
mSuggestions.push(sw);
+ if (!mHighestSuggestedWord || mHighestSuggestedWord->mScore < sw->mScore) {
+ mHighestSuggestedWord = sw;
+ }
}
SuggestedWord* top() {
@@ -88,6 +92,7 @@ class WordsPriorityQueue {
}
int outputSuggestions(int *frequencies, unsigned short *outputChars) {
+ mHighestSuggestedWord = 0;
const unsigned int size = min(MAX_WORDS, mSuggestions.size());
int index = size - 1;
while (!mSuggestions.empty() && index >= 0) {
@@ -116,6 +121,7 @@ class WordsPriorityQueue {
}
void clear() {
+ mHighestSuggestedWord = 0;
while (!mSuggestions.empty()) {
SuggestedWord* sw = mSuggestions.top();
if (DEBUG_WORDS_PRIORITY_QUEUE) {
@@ -134,6 +140,28 @@ class WordsPriorityQueue {
DUMP_WORD(mSuggestions.top()->mWord, mSuggestions.top()->mWordLength);
}
+ double getHighestNormalizedScore(const unsigned short* before, const int beforeLength,
+ unsigned short** outWord, int *outScore, int *outLength) {
+ if (!mHighestSuggestedWord) {
+ return 0.0;
+ }
+ SuggestedWord* sw = mHighestSuggestedWord;
+ const int score = sw->mScore;
+ unsigned short* word = sw->mWord;
+ const int wordLength = sw->mWordLength;
+ if (outScore) {
+ *outScore = score;
+ }
+ if (outWord) {
+ *outWord = word;
+ }
+ if (outLength) {
+ *outLength = wordLength;
+ }
+ return Correction::RankingAlgorithm::calcNormalizedScore(
+ before, beforeLength, word, wordLength, score);
+ }
+
private:
struct wordComparator {
bool operator ()(SuggestedWord * left, SuggestedWord * right) {
@@ -158,6 +186,7 @@ class WordsPriorityQueue {
const unsigned int MAX_WORDS;
const unsigned int MAX_WORD_LENGTH;
SuggestedWord* mSuggestedWords;
+ SuggestedWord* mHighestSuggestedWord;
};
}