Add a consolidated method to the Dictionary interface (A85)
Change-Id: I5d79021e69cc738e3013e31764ab0a59e15decdfmain
parent
2a37fb9d30
commit
82009901ea
|
@ -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<SuggestedWordInfo> 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.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,8 +240,9 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
|||
if (null == dictInfo) {
|
||||
return AndroidSpellCheckerService.getNotInDictEmptySuggestions();
|
||||
}
|
||||
final ArrayList<SuggestedWordInfo> suggestions = dictInfo.mDictionary.getWords(
|
||||
composer, prevWord, dictInfo.mProximityInfo);
|
||||
final ArrayList<SuggestedWordInfo> 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,
|
||||
|
|
Loading…
Reference in New Issue