diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 0835450c1..5229d14fa 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import android.text.TextUtils; + import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -49,6 +51,25 @@ public abstract class Dictionary { mDictType = dictType; } + /** + * Searches for suggestions for a given context. For the moment the context is only the + * previous word. + * @param composer the key sequence to match with coordinate info, as a WordComposer + * @param prevWord the previous word, or null if none + * @param proximityInfo the object for key proximity. May be ignored by some implementations. + * @return the list of suggestions (possibly null if none) + */ + // TODO: pass more context than just the previous word, to enable better suggestions (n-gram + // and more) + public ArrayList getSuggestions(final WordComposer composer, + final CharSequence prevWord, final ProximityInfo proximityInfo) { + if (composer.size() <= 1) { + return TextUtils.isEmpty(prevWord) ? null : getBigrams(composer, prevWord); + } else { + return getWords(composer, prevWord, proximityInfo); + } + } + /** * Searches for words in the dictionary that match the characters in the composer. Matched * words are returned as an ArrayList. diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 855971161..69b5f055a 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -188,15 +188,15 @@ public class Suggest { if (!TextUtils.isEmpty(prevWordForBigram)) { for (final String key : mDictionaries.keySet()) { final Dictionary dictionary = mDictionaries.get(key); - suggestionsSet.addAll(dictionary.getBigrams(wordComposerForLookup, - prevWordForBigram)); + suggestionsSet.addAll(dictionary.getSuggestions(wordComposerForLookup, + prevWordForBigram, proximityInfo)); } } } else { // At second character typed, search the unigrams (scores being affected by bigrams) for (final String key : mDictionaries.keySet()) { final Dictionary dictionary = mDictionaries.get(key); - suggestionsSet.addAll(dictionary.getWords( + suggestionsSet.addAll(dictionary.getSuggestions( wordComposerForLookup, prevWordForBigram, proximityInfo)); } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index c94e0081c..0171dc06d 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -240,8 +240,9 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { if (null == dictInfo) { return AndroidSpellCheckerService.getNotInDictEmptySuggestions(); } - final ArrayList suggestions = dictInfo.mDictionary.getWords( - composer, prevWord, dictInfo.mProximityInfo); + final ArrayList suggestions = + dictInfo.mDictionary.getSuggestions(composer, prevWord, + dictInfo.mProximityInfo); for (final SuggestedWordInfo suggestion : suggestions) { final String suggestionStr = suggestion.mWord.toString(); suggestionsGatherer.addWord(suggestionStr.toCharArray(), null, 0,