Skip to content
Snippets Groups Projects
Commit d82dcdc9 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add batch input dictionary lookup

Change-Id: I4da3c976838e8eb56c9ec80aafaaf54d759b7981
parent 5e573a1f
No related branches found
No related tags found
No related merge requests found
...@@ -188,32 +188,31 @@ public class BinaryDictionary extends Dictionary { ...@@ -188,32 +188,31 @@ public class BinaryDictionary extends Dictionary {
char[] outputChars, int[] scores, int[] spaceIndices) { char[] outputChars, int[] scores, int[] spaceIndices) {
if (!isValidDictionary()) return -1; if (!isValidDictionary()) return -1;
final int codesSize = codes.size();
// Won't deal with really long words.
if (codesSize > MAX_WORD_LENGTH - 1) return -1;
Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE); Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
for (int i = 0; i < codesSize; i++) {
mInputCodes[i] = codes.getCodeAt(i);
}
Arrays.fill(outputChars, (char) 0); Arrays.fill(outputChars, (char) 0);
Arrays.fill(scores, 0); Arrays.fill(scores, 0);
final InputPointers ips = codes.getInputPointers();
final boolean isGesture = codes.isBatchMode();
final int codesSize;
if (isGesture) {
codesSize = ips.getPointerSize();
} else {
codesSize = codes.size();
// Won't deal with really long words.
if (codesSize > MAX_WORD_LENGTH - 1) return -1;
for (int i = 0; i < codesSize; i++) {
mInputCodes[i] = codes.getCodeAt(i);
}
}
// TODO: toLowerCase in the native code // TODO: toLowerCase in the native code
final int[] prevWordCodePointArray = (null == prevWordForBigrams) final int[] prevWordCodePointArray = (null == prevWordForBigrams)
? null : StringUtils.toCodePointArray(prevWordForBigrams.toString()); ? null : StringUtils.toCodePointArray(prevWordForBigrams.toString());
int[] emptyArray = new int[codesSize];
Arrays.fill(emptyArray, 0);
//final int commitPoint = codes.getCommitPoint();
//codes.clearCommitPoint();
final InputPointers ips = codes.getInputPointers();
return 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 */, false, prevWordCodePointArray, mInputCodes, codesSize, 0 /* unused */, isGesture, prevWordCodePointArray,
mUseFullEditDistance, outputChars, scores, spaceIndices); mUseFullEditDistance, outputChars, scores, spaceIndices);
} }
......
...@@ -153,12 +153,23 @@ public class Suggest { ...@@ -153,12 +153,23 @@ public class Suggest {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
public SuggestedWords getSuggestedWords( public SuggestedWords getSuggestedWords(
final WordComposer wordComposer, CharSequence prevWordForBigram, final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) { final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
final boolean isPrediction = !wordComposer.isComposingWord();
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
if (wordComposer.isBatchMode()) {
return getSuggestedWordsForBatchInput(wordComposer, prevWordForBigram, proximityInfo);
} else {
return getSuggestedWordsForTypingInput(wordComposer, prevWordForBigram, proximityInfo,
isCorrectionEnabled);
}
}
// Retrieves suggestions for the typing input.
private SuggestedWords getSuggestedWordsForTypingInput(
final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
final boolean isPrediction = !wordComposer.isComposingWord();
final boolean isFirstCharCapitalized = final boolean isFirstCharCapitalized =
!isPrediction && wordComposer.isFirstCharCapitalized(); !isPrediction && wordComposer.isFirstCharCapitalized();
final boolean isAllUpperCase = !isPrediction && wordComposer.isAllUpperCase(); final boolean isAllUpperCase = !isPrediction && wordComposer.isAllUpperCase();
...@@ -285,6 +296,37 @@ public class Suggest { ...@@ -285,6 +296,37 @@ public class Suggest {
isPrediction); isPrediction);
} }
// Retrieves suggestions for the batch input.
private SuggestedWords getSuggestedWordsForBatchInput(
final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo) {
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
MAX_SUGGESTIONS);
// At second character typed, search the unigrams (scores being affected by bigrams)
for (final String key : mDictionaries.keySet()) {
// Skip UserUnigramDictionary and WhitelistDictionary to lookup
if (key.equals(Dictionary.TYPE_USER_HISTORY)
|| key.equals(Dictionary.TYPE_WHITELIST)) {
continue;
}
final Dictionary dictionary = mDictionaries.get(key);
suggestionsSet.addAll(dictionary.getSuggestions(
wordComposer, prevWordForBigram, proximityInfo));
}
final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<SuggestedWordInfo>(suggestionsSet);
SuggestedWordInfo.removeDups(suggestionsContainer);
return new SuggestedWords(suggestionsContainer,
true /* typedWordValid */,
true /* willAutoCorrect */,
false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */,
false /* isPrediction */);
}
private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo( private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo(
final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) { final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) {
final SuggestedWordInfo typedWordInfo = suggestions.get(0); final SuggestedWordInfo typedWordInfo = suggestions.get(0);
......
...@@ -37,6 +37,7 @@ public class WordComposer { ...@@ -37,6 +37,7 @@ public class WordComposer {
private final StringBuilder mTypedWord; private final StringBuilder mTypedWord;
private CharSequence mAutoCorrection; private CharSequence mAutoCorrection;
private boolean mIsResumed; private boolean mIsResumed;
private boolean mIsBatchMode;
// Cache these values for performance // Cache these values for performance
private int mCapsCount; private int mCapsCount;
...@@ -55,6 +56,7 @@ public class WordComposer { ...@@ -55,6 +56,7 @@ public class WordComposer {
mAutoCorrection = null; mAutoCorrection = null;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
mIsResumed = false; mIsResumed = false;
mIsBatchMode = false;
refreshSize(); refreshSize();
} }
...@@ -67,6 +69,7 @@ public class WordComposer { ...@@ -67,6 +69,7 @@ public class WordComposer {
mAutoCapitalized = source.mAutoCapitalized; mAutoCapitalized = source.mAutoCapitalized;
mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount; mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount;
mIsResumed = source.mIsResumed; mIsResumed = source.mIsResumed;
mIsBatchMode = source.mIsBatchMode;
refreshSize(); refreshSize();
} }
...@@ -80,6 +83,7 @@ public class WordComposer { ...@@ -80,6 +83,7 @@ public class WordComposer {
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
mTrailingSingleQuotesCount = 0; mTrailingSingleQuotesCount = 0;
mIsResumed = false; mIsResumed = false;
mIsBatchMode = false;
refreshSize(); refreshSize();
} }
...@@ -140,6 +144,12 @@ public class WordComposer { ...@@ -140,6 +144,12 @@ public class WordComposer {
mAutoCorrection = null; mAutoCorrection = null;
} }
// TODO: We may want to have appendBatchInputPointers() as well.
public void setBatchInputPointers(InputPointers batchPointers) {
mInputPointers.copy(batchPointers);
mIsBatchMode = true;
}
/** /**
* Internal method to retrieve reasonable proximity info for a character. * Internal method to retrieve reasonable proximity info for a character.
*/ */
...@@ -312,4 +322,8 @@ public class WordComposer { ...@@ -312,4 +322,8 @@ public class WordComposer {
mAutoCorrection = null; // This will be filled by the next call to updateSuggestion. mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
mIsResumed = true; mIsResumed = true;
} }
public boolean isBatchMode() {
return mIsBatchMode;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment