Merge "Pull up some identical code (A98)"
This commit is contained in:
commit
722b00275d
1 changed files with 23 additions and 39 deletions
|
@ -114,16 +114,32 @@ public class BinaryDictionary extends Dictionary {
|
||||||
// TODO: toLowerCase in the native code
|
// TODO: toLowerCase in the native code
|
||||||
final int[] prevWordCodePointArray = (null == prevWord)
|
final int[] prevWordCodePointArray = (null == prevWord)
|
||||||
? null : StringUtils.toCodePointArray(prevWord.toString());
|
? null : StringUtils.toCodePointArray(prevWord.toString());
|
||||||
|
final int count;
|
||||||
if (composer.size() <= 1) {
|
if (composer.size() <= 1) {
|
||||||
return TextUtils.isEmpty(prevWord) ? null : getBigramsInternal(composer,
|
count = TextUtils.isEmpty(prevWord) ? -1 : getBigramsInternal(composer,
|
||||||
prevWordCodePointArray);
|
prevWordCodePointArray);
|
||||||
} else {
|
} else {
|
||||||
return getWordsInternal(composer, prevWordCodePointArray, proximityInfo);
|
count = getWordsInternal(composer, prevWordCodePointArray, proximityInfo);
|
||||||
}
|
}
|
||||||
|
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
||||||
|
for (int j = 0; j < count; ++j) {
|
||||||
|
if (composer.size() > 0 && mOutputScores[j] < 1) break;
|
||||||
|
final int start = j * MAX_WORD_LENGTH;
|
||||||
|
int len = 0;
|
||||||
|
while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
|
||||||
|
++len;
|
||||||
|
}
|
||||||
|
if (len > 0) {
|
||||||
|
suggestions.add(new SuggestedWordInfo(
|
||||||
|
new String(mOutputChars, start, len),
|
||||||
|
mOutputScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move to native code
|
// TODO: move to native code
|
||||||
private ArrayList<SuggestedWordInfo> getBigramsInternal(final WordComposer codes,
|
private int getBigramsInternal(final WordComposer codes,
|
||||||
final int[] previousWord) {
|
final int[] previousWord) {
|
||||||
int codesSize = codes.size();
|
int codesSize = codes.size();
|
||||||
if (codesSize > 0) {
|
if (codesSize > 0) {
|
||||||
|
@ -135,27 +151,12 @@ public class BinaryDictionary extends Dictionary {
|
||||||
if (count > MAX_BIGRAMS) {
|
if (count > MAX_BIGRAMS) {
|
||||||
count = MAX_BIGRAMS;
|
count = MAX_BIGRAMS;
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
|
||||||
for (int j = 0; j < count; ++j) {
|
|
||||||
if (codesSize > 0 && mOutputScores[j] < 1) break;
|
|
||||||
final int start = j * MAX_WORD_LENGTH;
|
|
||||||
int len = 0;
|
|
||||||
while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
if (len > 0) {
|
|
||||||
suggestions.add(new SuggestedWordInfo(
|
|
||||||
new String(mOutputChars, start, len),
|
|
||||||
mOutputScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move to native code
|
// TODO: move to native code
|
||||||
// proximityInfo and/or prevWordForBigrams may not be null.
|
// proximityInfo and/or prevWordForBigrams may not be null.
|
||||||
private ArrayList<SuggestedWordInfo> getWordsInternal(final WordComposer codes,
|
private int getWordsInternal(final WordComposer codes,
|
||||||
final int[] prevWord, final ProximityInfo proximityInfo) {
|
final int[] prevWord, final ProximityInfo proximityInfo) {
|
||||||
final InputPointers ips = codes.getInputPointers();
|
final InputPointers ips = codes.getInputPointers();
|
||||||
final boolean isGesture = codes.isBatchMode();
|
final boolean isGesture = codes.isBatchMode();
|
||||||
|
@ -165,33 +166,16 @@ public class BinaryDictionary extends Dictionary {
|
||||||
} else {
|
} else {
|
||||||
codesSize = codes.size();
|
codesSize = codes.size();
|
||||||
// Won't deal with really long words.
|
// Won't deal with really long words.
|
||||||
if (codesSize > MAX_WORD_LENGTH - 1) return null;
|
if (codesSize > MAX_WORD_LENGTH - 1) return -1;
|
||||||
for (int i = 0; i < codesSize; i++) {
|
for (int i = 0; i < codesSize; i++) {
|
||||||
mInputCodes[i] = codes.getCodeAt(i);
|
mInputCodes[i] = codes.getCodeAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int count = getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
|
return getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
|
||||||
ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
|
ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
|
||||||
mInputCodes, codesSize, 0 /* unused */, isGesture, prevWord,
|
mInputCodes, codesSize, 0 /* unused */, isGesture, prevWord,
|
||||||
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices);
|
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices);
|
||||||
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
|
||||||
for (int j = 0; j < count; ++j) {
|
|
||||||
if (mOutputScores[j] < 1) break;
|
|
||||||
final int start = j * MAX_WORD_LENGTH;
|
|
||||||
int len = 0;
|
|
||||||
while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
if (len > 0) {
|
|
||||||
// TODO: actually get the kind from native code
|
|
||||||
suggestions.add(new SuggestedWordInfo(
|
|
||||||
new String(mOutputChars, start, len),
|
|
||||||
mOutputScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package for test */ boolean isValidDictionary() {
|
/* package for test */ boolean isValidDictionary() {
|
||||||
|
|
Loading…
Reference in a new issue