aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/spellcheck
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java56
1 files changed, 42 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 0e3bf8011..802322ccd 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -99,11 +99,13 @@ public class AndroidSpellCheckerService extends SpellCheckerService
// List of the supported languages and their associated script. We won't check
// words written in another script than the selected script, because we know we
// don't have those in our dictionary so we will underline everything and we
- // will never have any suggestions, so it makes no sense checking them.
+ // will never have any suggestions, so it makes no sense checking them, and this
+ // is done in {@link #shouldFilterOut}. Also, the script is used to choose which
+ // proximity to pass to the dictionary descent algorithm.
+ // IMPORTANT: this only contains languages - do not write countries in there.
+ // Only the language is searched from the map.
mLanguageToScript = new TreeMap<String, Integer>();
mLanguageToScript.put("en", SCRIPT_LATIN);
- mLanguageToScript.put("en_US", SCRIPT_LATIN);
- mLanguageToScript.put("en_GB", SCRIPT_LATIN);
mLanguageToScript.put("fr", SCRIPT_LATIN);
mLanguageToScript.put("de", SCRIPT_LATIN);
mLanguageToScript.put("nl", SCRIPT_LATIN);
@@ -111,7 +113,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
mLanguageToScript.put("es", SCRIPT_LATIN);
mLanguageToScript.put("it", SCRIPT_LATIN);
mLanguageToScript.put("hr", SCRIPT_LATIN);
- mLanguageToScript.put("pt_BR", SCRIPT_LATIN);
+ mLanguageToScript.put("pt", SCRIPT_LATIN);
mLanguageToScript.put("ru", SCRIPT_CYRILLIC);
// TODO: Make a persian proximity, and activate the Farsi subtype.
// mLanguageToScript.put("fa", SCRIPT_PERSIAN);
@@ -152,7 +154,13 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private void startUsingContactsDictionaryLocked() {
if (null == mContactsDictionary) {
- mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this);
+ if (LatinIME.USE_BINARY_CONTACTS_DICTIONARY) {
+ // TODO: use the right locale for each session
+ mContactsDictionary =
+ new SynchronouslyLoadedContactsBinaryDictionary(this, Locale.getDefault());
+ } else {
+ mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this);
+ }
}
final Iterator<WeakReference<DictionaryCollection>> iterator =
mDictionaryCollectionsList.iterator();
@@ -430,7 +438,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService
// TODO: revert to the concrete type when USE_BINARY_CONTACTS_DICTIONARY is no
// longer needed
if (LatinIME.USE_BINARY_CONTACTS_DICTIONARY) {
- mContactsDictionary = new SynchronouslyLoadedContactsBinaryDictionary(this);
+ // TODO: use the right locale. We can't do it right now because the
+ // spell checker is reusing the contacts dictionary across sessions
+ // without regard for their locale, so we need to fix that first.
+ mContactsDictionary = new SynchronouslyLoadedContactsBinaryDictionary(this,
+ Locale.getDefault());
} else {
mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this);
}
@@ -484,20 +496,32 @@ public class AndroidSpellCheckerService extends SpellCheckerService
}
private static class SuggestionsCache {
+ private static final char CHAR_DELIMITER = '\uFFFC';
private static final int MAX_CACHE_SIZE = 50;
- // TODO: support bigram
private final LruCache<String, SuggestionsParams> mUnigramSuggestionsInfoCache =
new LruCache<String, SuggestionsParams>(MAX_CACHE_SIZE);
- public SuggestionsParams getSuggestionsFromCache(String query) {
- return mUnigramSuggestionsInfoCache.get(query);
+ // TODO: Support n-gram input
+ private static String generateKey(String query, String prevWord) {
+ if (TextUtils.isEmpty(query) || TextUtils.isEmpty(prevWord)) {
+ return query;
+ }
+ return query + CHAR_DELIMITER + prevWord;
+ }
+
+ // TODO: Support n-gram input
+ public SuggestionsParams getSuggestionsFromCache(String query, String prevWord) {
+ return mUnigramSuggestionsInfoCache.get(generateKey(query, prevWord));
}
- public void putSuggestionsToCache(String query, String[] suggestions, int flags) {
+ // TODO: Support n-gram input
+ public void putSuggestionsToCache(
+ String query, String prevWord, String[] suggestions, int flags) {
if (suggestions == null || TextUtils.isEmpty(query)) {
return;
}
- mUnigramSuggestionsInfoCache.put(query, new SuggestionsParams(suggestions, flags));
+ mUnigramSuggestionsInfoCache.put(
+ generateKey(query, prevWord), new SuggestionsParams(suggestions, flags));
}
}
@@ -592,6 +616,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final ArrayList<Integer> additionalLengths = new ArrayList<Integer>();
final ArrayList<SuggestionsInfo> additionalSuggestionsInfos =
new ArrayList<SuggestionsInfo>();
+ String currentWord = null;
for (int i = 0; i < N; ++i) {
final SuggestionsInfo si = ssi.getSuggestionsInfoAt(i);
final int flags = si.getSuggestionsAttributes();
@@ -601,6 +626,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final int offset = ssi.getOffsetAt(i);
final int length = ssi.getLengthAt(i);
final String subText = typedText.substring(offset, offset + length);
+ final String prevWord = currentWord;
+ currentWord = subText;
if (!subText.contains(SINGLE_QUOTE)) {
continue;
}
@@ -614,7 +641,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
if (TextUtils.isEmpty(splitText)) {
continue;
}
- if (mSuggestionsCache.getSuggestionsFromCache(splitText) == null) {
+ if (mSuggestionsCache.getSuggestionsFromCache(
+ splitText, prevWord) == null) {
continue;
}
final int newLength = splitText.length();
@@ -710,7 +738,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
try {
final String inText = textInfo.getText();
final SuggestionsParams cachedSuggestionsParams =
- mSuggestionsCache.getSuggestionsFromCache(inText);
+ mSuggestionsCache.getSuggestionsFromCache(inText, prevWord);
if (cachedSuggestionsParams != null) {
if (DBG) {
Log.d(TAG, "Cache hit: " + inText + ", " + cachedSuggestionsParams.mFlags);
@@ -802,7 +830,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
.getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS()
: 0);
final SuggestionsInfo retval = new SuggestionsInfo(flags, result.mSuggestions);
- mSuggestionsCache.putSuggestionsToCache(text, result.mSuggestions, flags);
+ mSuggestionsCache.putSuggestionsToCache(text, prevWord, result.mSuggestions, flags);
return retval;
} catch (RuntimeException e) {
// Don't kill the keyboard if there is a bug in the spell checker