aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-09-19 23:19:47 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-19 23:19:47 -0700
commitd2547c68884860d19429f40ec1fd5fbfadebc366 (patch)
treef1d111fab3b16b2b7cf2ed9af63fd93b237542ec /java/src
parent8efe9bb15a9b31587aa939eb2497781ce5703dfe (diff)
parente897e4d3422c8d9d8b6f051376cc2ba16e4d5945 (diff)
downloadlatinime-d2547c68884860d19429f40ec1fd5fbfadebc366.tar.gz
latinime-d2547c68884860d19429f40ec1fd5fbfadebc366.tar.xz
latinime-d2547c68884860d19429f40ec1fd5fbfadebc366.zip
Merge "Have the spell checker report IN_DICT correctly"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java44
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java9
2 files changed, 33 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 1e5b87763..915c40572 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -60,8 +60,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private static final int CAPITALIZE_ALL = 2; // All caps
private final static String[] EMPTY_STRING_ARRAY = new String[0];
- private final static SuggestionsInfo EMPTY_SUGGESTIONS_INFO =
+ private final static SuggestionsInfo NOT_IN_DICT_EMPTY_SUGGESTIONS =
new SuggestionsInfo(0, EMPTY_STRING_ARRAY);
+ private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS =
+ new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY,
+ EMPTY_STRING_ARRAY);
private Map<String, DictionaryPool> mDictionaryPools =
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
private Map<String, Dictionary> mUserDictionaries =
@@ -330,7 +333,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
try {
final String text = textInfo.getText();
- if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO;
+ if (shouldFilterOut(text)) {
+ final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull();
+ if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS
+ : NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ }
final SuggestionsGatherer suggestionsGatherer =
new SuggestionsGatherer(suggestionsLimit);
@@ -353,23 +361,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final int capitalizeType = getCapitalizationType(text);
boolean isInDict = true;
- try {
- final DictAndProximity dictInfo = mDictionaryPool.take();
- dictInfo.mDictionary.getWords(composer, suggestionsGatherer,
- dictInfo.mProximityInfo);
- isInDict = dictInfo.mDictionary.isValidWord(text);
- if (!isInDict && CAPITALIZE_NONE != capitalizeType) {
- // We want to test the word again if it's all caps or first caps only.
- // If it's fully down, we already tested it, if it's mixed case, we don't
- // want to test a lowercase version of it.
- isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale));
- }
- if (!mDictionaryPool.offer(dictInfo)) {
- Log.e(TAG, "Can't re-insert a dictionary into its pool");
- }
- } catch (InterruptedException e) {
- // I don't think this can happen.
- return EMPTY_SUGGESTIONS_INFO;
+ final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull();
+ if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
+ dictInfo.mDictionary.getWords(composer, suggestionsGatherer,
+ dictInfo.mProximityInfo);
+ isInDict = dictInfo.mDictionary.isValidWord(text);
+ if (!isInDict && CAPITALIZE_NONE != capitalizeType) {
+ // We want to test the word again if it's all caps or first caps only.
+ // If it's fully down, we already tested it, if it's mixed case, we don't
+ // want to test a lowercase version of it.
+ isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale));
+ }
+ if (!mDictionaryPool.offer(dictInfo)) {
+ Log.e(TAG, "Can't re-insert a dictionary into its pool");
}
final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text,
@@ -396,7 +400,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
throw e;
} else {
Log.e(TAG, "Exception while spellcheking: " + e);
- return EMPTY_SUGGESTIONS_INFO;
+ return NOT_IN_DICT_EMPTY_SUGGESTIONS;
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
index ee294f6b0..dec18c1d5 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
@@ -56,6 +56,15 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> {
}
}
+ // Convenience method
+ public DictAndProximity takeOrGetNull() {
+ try {
+ return take();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+
public void close() {
synchronized(this) {
mClosed = true;