am dc2fb6bc
: Merge "Pass the type from native code all the way to Java." into jb-mr1-dev
* commit 'dc2fb6bc6d0c071b8023d62291becf2e2d59535c': Pass the type from native code all the way to Java.
This commit is contained in:
commit
1599feda42
3 changed files with 23 additions and 17 deletions
|
@ -144,9 +144,10 @@ public class BinaryDictionary extends Dictionary {
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
final int score = SuggestedWordInfo.KIND_WHITELIST == mOutputTypes[j]
|
||||||
|
? SuggestedWordInfo.MAX_SCORE : mOutputScores[j];
|
||||||
suggestions.add(new SuggestedWordInfo(
|
suggestions.add(new SuggestedWordInfo(
|
||||||
new String(mOutputChars, start, len),
|
new String(mOutputChars, start, len), score, mOutputTypes[j], mDictType));
|
||||||
mOutputScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
|
|
|
@ -63,8 +63,8 @@ static inline unsigned int getCodesBufferSize(const int *codes, const int codesS
|
||||||
|
|
||||||
// TODO: This needs to take a const unsigned short* and not tinker with its contents
|
// TODO: This needs to take a const unsigned short* and not tinker with its contents
|
||||||
static inline void addWord(
|
static inline void addWord(
|
||||||
unsigned short *word, int length, int frequency, WordsPriorityQueue *queue) {
|
unsigned short *word, int length, int frequency, WordsPriorityQueue *queue, int type) {
|
||||||
queue->push(frequency, word, length);
|
queue->push(frequency, word, length, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the replacement code point for a digraph, or 0 if none.
|
// Return the replacement code point for a digraph, or 0 if none.
|
||||||
|
@ -213,8 +213,8 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
|
||||||
AKLOGI("Max normalized score = %f", ns);
|
AKLOGI("Max normalized score = %f", ns);
|
||||||
}
|
}
|
||||||
const int suggestedWordsCount =
|
const int suggestedWordsCount =
|
||||||
queuePool.getMasterQueue()->outputSuggestions(
|
queuePool.getMasterQueue()->outputSuggestions(masterCorrection.getPrimaryInputWord(),
|
||||||
masterCorrection.getPrimaryInputWord(), codesSize, frequencies, outWords);
|
codesSize, frequencies, outWords, outputTypes);
|
||||||
|
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
float ns = queuePool.getMasterQueue()->getHighestNormalizedScore(
|
float ns = queuePool.getMasterQueue()->getHighestNormalizedScore(
|
||||||
|
@ -391,7 +391,8 @@ inline void UnigramDictionary::onTerminal(const int probability,
|
||||||
const int finalProbability =
|
const int finalProbability =
|
||||||
correction->getFinalProbability(probability, &wordPointer, &wordLength);
|
correction->getFinalProbability(probability, &wordPointer, &wordLength);
|
||||||
if (finalProbability != NOT_A_PROBABILITY) {
|
if (finalProbability != NOT_A_PROBABILITY) {
|
||||||
addWord(wordPointer, wordLength, finalProbability, masterQueue);
|
addWord(wordPointer, wordLength, finalProbability, masterQueue,
|
||||||
|
Dictionary::KIND_CORRECTION);
|
||||||
|
|
||||||
const int shortcutProbability = finalProbability > 0 ? finalProbability - 1 : 0;
|
const int shortcutProbability = finalProbability > 0 ? finalProbability - 1 : 0;
|
||||||
// Please note that the shortcut candidates will be added to the master queue only.
|
// Please note that the shortcut candidates will be added to the master queue only.
|
||||||
|
@ -409,7 +410,7 @@ inline void UnigramDictionary::onTerminal(const int probability,
|
||||||
const int shortcutTargetStringLength = iterator.getNextShortcutTarget(
|
const int shortcutTargetStringLength = iterator.getNextShortcutTarget(
|
||||||
MAX_WORD_LENGTH_INTERNAL, shortcutTarget);
|
MAX_WORD_LENGTH_INTERNAL, shortcutTarget);
|
||||||
addWord(shortcutTarget, shortcutTargetStringLength, shortcutProbability,
|
addWord(shortcutTarget, shortcutTargetStringLength, shortcutProbability,
|
||||||
masterQueue);
|
masterQueue, Dictionary::KIND_CORRECTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +425,7 @@ inline void UnigramDictionary::onTerminal(const int probability,
|
||||||
}
|
}
|
||||||
const int finalProbability = correction->getFinalProbabilityForSubQueue(
|
const int finalProbability = correction->getFinalProbabilityForSubQueue(
|
||||||
probability, &wordPointer, &wordLength, inputIndex);
|
probability, &wordPointer, &wordLength, inputIndex);
|
||||||
addWord(wordPointer, wordLength, finalProbability, subQueue);
|
addWord(wordPointer, wordLength, finalProbability, subQueue, Dictionary::KIND_CORRECTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,7 +573,8 @@ int UnigramDictionary::getSubStringSuggestion(
|
||||||
AKLOGI("Split two words: freq = %d, length = %d, %d, isSpace ? %d", pairFreq,
|
AKLOGI("Split two words: freq = %d, length = %d, %d, isSpace ? %d", pairFreq,
|
||||||
inputLength, tempOutputWordLength, isSpaceProximity);
|
inputLength, tempOutputWordLength, isSpaceProximity);
|
||||||
}
|
}
|
||||||
addWord(outputWord, tempOutputWordLength, pairFreq, queuePool->getMasterQueue());
|
addWord(outputWord, tempOutputWordLength, pairFreq, queuePool->getMasterQueue(),
|
||||||
|
Dictionary::KIND_CORRECTION);
|
||||||
}
|
}
|
||||||
return FLAG_MULTIPLE_SUGGEST_CONTINUE;
|
return FLAG_MULTIPLE_SUGGEST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,14 @@ class WordsPriorityQueue {
|
||||||
unsigned short mWord[MAX_WORD_LENGTH_INTERNAL];
|
unsigned short mWord[MAX_WORD_LENGTH_INTERNAL];
|
||||||
int mWordLength;
|
int mWordLength;
|
||||||
bool mUsed;
|
bool mUsed;
|
||||||
|
int mType;
|
||||||
|
|
||||||
void setParams(int score, unsigned short *word, int wordLength) {
|
void setParams(int score, unsigned short *word, int wordLength, int type) {
|
||||||
mScore = score;
|
mScore = score;
|
||||||
mWordLength = wordLength;
|
mWordLength = wordLength;
|
||||||
memcpy(mWord, word, sizeof(unsigned short) * wordLength);
|
memcpy(mWord, word, sizeof(unsigned short) * wordLength);
|
||||||
mUsed = true;
|
mUsed = true;
|
||||||
|
mType = type;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +58,7 @@ class WordsPriorityQueue {
|
||||||
delete[] mSuggestedWords;
|
delete[] mSuggestedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(int score, unsigned short *word, int wordLength) {
|
void push(int score, unsigned short *word, int wordLength, int type) {
|
||||||
SuggestedWord *sw = 0;
|
SuggestedWord *sw = 0;
|
||||||
if (mSuggestions.size() >= MAX_WORDS) {
|
if (mSuggestions.size() >= MAX_WORDS) {
|
||||||
sw = mSuggestions.top();
|
sw = mSuggestions.top();
|
||||||
|
@ -69,9 +71,9 @@ class WordsPriorityQueue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sw == 0) {
|
if (sw == 0) {
|
||||||
sw = getFreeSuggestedWord(score, word, wordLength);
|
sw = getFreeSuggestedWord(score, word, wordLength, type);
|
||||||
} else {
|
} else {
|
||||||
sw->setParams(score, word, wordLength);
|
sw->setParams(score, word, wordLength, type);
|
||||||
}
|
}
|
||||||
if (sw == 0) {
|
if (sw == 0) {
|
||||||
AKLOGE("SuggestedWord is accidentally null.");
|
AKLOGE("SuggestedWord is accidentally null.");
|
||||||
|
@ -94,7 +96,7 @@ class WordsPriorityQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
int outputSuggestions(const unsigned short *before, const int beforeLength,
|
int outputSuggestions(const unsigned short *before, const int beforeLength,
|
||||||
int *frequencies, unsigned short *outputChars) {
|
int *frequencies, unsigned short *outputChars, int* outputTypes) {
|
||||||
mHighestSuggestedWord = 0;
|
mHighestSuggestedWord = 0;
|
||||||
const unsigned int size = min(
|
const unsigned int size = min(
|
||||||
MAX_WORDS, static_cast<unsigned int>(mSuggestions.size()));
|
MAX_WORDS, static_cast<unsigned int>(mSuggestions.size()));
|
||||||
|
@ -140,6 +142,7 @@ class WordsPriorityQueue {
|
||||||
const unsigned int wordLength = sw->mWordLength;
|
const unsigned int wordLength = sw->mWordLength;
|
||||||
char *targetAdr = (char*) outputChars + i * MAX_WORD_LENGTH * sizeof(short);
|
char *targetAdr = (char*) outputChars + i * MAX_WORD_LENGTH * sizeof(short);
|
||||||
frequencies[i] = sw->mScore;
|
frequencies[i] = sw->mScore;
|
||||||
|
outputTypes[i] = sw->mType;
|
||||||
memcpy(targetAdr, sw->mWord, (wordLength) * sizeof(short));
|
memcpy(targetAdr, sw->mWord, (wordLength) * sizeof(short));
|
||||||
if (wordLength < MAX_WORD_LENGTH) {
|
if (wordLength < MAX_WORD_LENGTH) {
|
||||||
((unsigned short*) targetAdr)[wordLength] = 0;
|
((unsigned short*) targetAdr)[wordLength] = 0;
|
||||||
|
@ -191,10 +194,10 @@ class WordsPriorityQueue {
|
||||||
};
|
};
|
||||||
|
|
||||||
SuggestedWord *getFreeSuggestedWord(int score, unsigned short *word,
|
SuggestedWord *getFreeSuggestedWord(int score, unsigned short *word,
|
||||||
int wordLength) {
|
int wordLength, int type) {
|
||||||
for (unsigned int i = 0; i < MAX_WORD_LENGTH; ++i) {
|
for (unsigned int i = 0; i < MAX_WORD_LENGTH; ++i) {
|
||||||
if (!mSuggestedWords[i].mUsed) {
|
if (!mSuggestedWords[i].mUsed) {
|
||||||
mSuggestedWords[i].setParams(score, word, wordLength);
|
mSuggestedWords[i].setParams(score, word, wordLength, type);
|
||||||
return &mSuggestedWords[i];
|
return &mSuggestedWords[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue