aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-07-09 16:34:49 +0900
committerJean Chalard <jchalard@google.com>2012-07-10 18:57:12 +0900
commit82009901eaa1fd0da95b25c900f8ff12fda9e679 (patch)
tree4bcaceffa6a14b6e96bf2bd32fa754d71658008f /java/src
parent2a37fb9d30848aee42757546e8478cb7a9e45bc6 (diff)
downloadlatinime-82009901eaa1fd0da95b25c900f8ff12fda9e679.tar.gz
latinime-82009901eaa1fd0da95b25c900f8ff12fda9e679.tar.xz
latinime-82009901eaa1fd0da95b25c900f8ff12fda9e679.zip
Add a consolidated method to the Dictionary interface (A85)
Change-Id: I5d79021e69cc738e3013e31764ab0a59e15decdf
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Dictionary.java21
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java6
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java5
3 files changed, 27 insertions, 5 deletions
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;
@@ -50,6 +52,25 @@ public abstract class Dictionary {
}
/**
+ * 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.
* @param composer the key sequence to match with coordinate info, as a WordComposer
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<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,