aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-07-10 10:46:13 +0900
committerTadashi G. Takaoka <takaoka@google.com>2012-07-10 20:01:28 +0900
commitd82dcdc9246b340c4b355e34efc6079f3278efa6 (patch)
tree4e374f9c8cf718ffc9c8c7514241186ed81b2c00 /java/src/com/android/inputmethod/latin/Suggest.java
parent5e573a1f0a63c017c7b0e4c4314235bd87c9363c (diff)
downloadlatinime-d82dcdc9246b340c4b355e34efc6079f3278efa6.tar.gz
latinime-d82dcdc9246b340c4b355e34efc6079f3278efa6.tar.xz
latinime-d82dcdc9246b340c4b355e34efc6079f3278efa6.zip
Add batch input dictionary lookup
Change-Id: I4da3c976838e8eb56c9ec80aafaaf54d759b7981
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java46
1 files changed, 44 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index c4a7787fa..31c6000e3 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -153,12 +153,23 @@ public class Suggest {
mAutoCorrectionThreshold = threshold;
}
- // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
public SuggestedWords getSuggestedWords(
final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
- final boolean isPrediction = !wordComposer.isComposingWord();
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 =
!isPrediction && wordComposer.isFirstCharCapitalized();
final boolean isAllUpperCase = !isPrediction && wordComposer.isAllUpperCase();
@@ -285,6 +296,37 @@ public class Suggest {
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(
final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) {
final SuggestedWordInfo typedWordInfo = suggestions.get(0);