aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java86
1 files changed, 64 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index f810eccf4..31c6000e3 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -153,14 +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,
- // TODO: remove isPrediction parameter. It effectively means the same thing
- // as wordComposer.size() <= 1
- final boolean isPrediction) {
+ final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
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();
@@ -174,32 +183,29 @@ public class Suggest {
: typedWord;
LatinImeLogger.onAddSuggestedWord(typedWord, Dictionary.TYPE_USER_TYPED);
- if (wordComposer.size() <= 1 && isCorrectionEnabled) {
+ final WordComposer wordComposerForLookup;
+ if (trailingSingleQuotesCount > 0) {
+ wordComposerForLookup = new WordComposer(wordComposer);
+ for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
+ wordComposerForLookup.deleteLast();
+ }
+ } else {
+ wordComposerForLookup = wordComposer;
+ }
+ if (wordComposerForLookup.size() <= 1) {
// At first character typed, search only the bigrams
if (!TextUtils.isEmpty(prevWordForBigram)) {
for (final String key : mDictionaries.keySet()) {
final Dictionary dictionary = mDictionaries.get(key);
- suggestionsSet.addAll(dictionary.getBigrams(wordComposer, prevWordForBigram));
- }
- }
- } else if (wordComposer.size() > 1) {
- final WordComposer wordComposerForLookup;
- if (trailingSingleQuotesCount > 0) {
- wordComposerForLookup = new WordComposer(wordComposer);
- for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
- wordComposerForLookup.deleteLast();
+ suggestionsSet.addAll(dictionary.getSuggestions(wordComposerForLookup,
+ prevWordForBigram, proximityInfo));
}
- } else {
- wordComposerForLookup = wordComposer;
}
+ } else {
// 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.getWords(
+ suggestionsSet.addAll(dictionary.getSuggestions(
wordComposerForLookup, prevWordForBigram, proximityInfo));
}
}
@@ -216,6 +222,11 @@ public class Suggest {
mWhiteListDictionary.getWhitelistedWord(consideredWord);
final boolean hasAutoCorrection;
+ // TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
+ // any attempt to do auto-correction is already shielded with a test for this flag; at the
+ // same time, it feels wrong that the SuggestedWord object includes information about
+ // the current settings. It may also be useful to know, when the setting is off, whether
+ // the word *would* have been auto-corrected.
if (!isCorrectionEnabled || !allowsToBeAutoCorrected || wordComposer.isMostlyCaps()
|| wordComposer.isResumed() || !hasMainDictionary()) {
// If we don't have a main dictionary, we never want to auto-correct. The reason for
@@ -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);