aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/SuggestHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/SuggestHelper.java')
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestHelper.java77
1 files changed, 17 insertions, 60 deletions
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 759bfa18a..c734f07fd 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -38,49 +38,15 @@ public class SuggestHelper {
private final String TAG;
/** Uses main dictionary only **/
- public SuggestHelper(String tag, Context context, int[] resId) {
+ public SuggestHelper(String tag, Context context, int resId) {
TAG = tag;
- InputStream[] is = null;
- try {
- // merging separated dictionary into one if dictionary is separated
- int total = 0;
- is = new InputStream[resId.length];
- for (int i = 0; i < resId.length; i++) {
- is[i] = context.getResources().openRawResource(resId[i]);
- total += is[i].available();
- }
-
- ByteBuffer byteBuffer =
- ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder());
- int got = 0;
- for (int i = 0; i < resId.length; i++) {
- got += Channels.newChannel(is[i]).read(byteBuffer);
- }
- if (got != total) {
- Log.w(TAG, "Read " + got + " bytes, expected " + total);
- } else {
- mSuggest = new Suggest(context, byteBuffer);
- Log.i(TAG, "Created mSuggest " + total + " bytes");
- }
- } catch (IOException e) {
- Log.w(TAG, "No available memory for binary dictionary");
- } finally {
- try {
- if (is != null) {
- for (int i = 0; i < is.length; i++) {
- is[i].close();
- }
- }
- } catch (IOException e) {
- Log.w(TAG, "Failed to close input stream");
- }
- }
+ mSuggest = new Suggest(context, resId);
mSuggest.setAutoTextEnabled(false);
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
}
/** Uses both main dictionary and user-bigram dictionary **/
- public SuggestHelper(String tag, Context context, int[] resId, int userBigramMax,
+ public SuggestHelper(String tag, Context context, int resId, int userBigramMax,
int userBigramDelete) {
this(tag, context, resId);
mUserBigram = new UserBigramDictionary(context, null, Locale.US.toString(),
@@ -116,37 +82,30 @@ public class SuggestHelper {
return word;
}
- private void showList(String title, List<CharSequence> suggestions) {
- Log.i(TAG, title);
- for (int i = 0; i < suggestions.size(); i++) {
- Log.i(title, suggestions.get(i) + ", ");
- }
- }
-
- private boolean isDefaultSuggestion(List<CharSequence> suggestions, CharSequence word) {
+ private boolean isDefaultSuggestion(SuggestedWords suggestions, CharSequence word) {
// Check if either the word is what you typed or the first alternative
return suggestions.size() > 0 &&
(/*TextUtils.equals(suggestions.get(0), word) || */
- (suggestions.size() > 1 && TextUtils.equals(suggestions.get(1), word)));
+ (suggestions.size() > 1 && TextUtils.equals(suggestions.getWord(1), word)));
}
boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null);
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
return isDefaultSuggestion(suggestions, expected);
}
boolean isDefaultCorrection(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null);
- return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
+ return isDefaultSuggestion(suggestions, expected) && mSuggest.hasAutoCorrection();
}
boolean isASuggestion(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, null);
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
for (int i = 1; i < suggestions.size(); i++) {
- if (TextUtils.equals(suggestions.get(i), expected)) return true;
+ if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
}
return false;
}
@@ -154,7 +113,7 @@ public class SuggestHelper {
private void getBigramSuggestions(CharSequence previous, CharSequence typed) {
if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) {
WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0)));
- mSuggest.getSuggestions(null, firstChar, false, previous);
+ mSuggest.getSuggestions(null, firstChar, previous);
}
}
@@ -162,7 +121,7 @@ public class SuggestHelper {
CharSequence expected) {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous);
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
return isDefaultSuggestion(suggestions, expected);
}
@@ -170,17 +129,17 @@ public class SuggestHelper {
CharSequence expected) {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous);
- return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
+ return isDefaultSuggestion(suggestions, expected) && mSuggest.hasAutoCorrection();
}
boolean isASuggestion(CharSequence previous, CharSequence typed,
CharSequence expected) {
WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed);
- List<CharSequence> suggestions = mSuggest.getSuggestions(null, word, false, previous);
+ SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
for (int i = 1; i < suggestions.size(); i++) {
- if (TextUtils.equals(suggestions.get(i), expected)) return true;
+ if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
}
return false;
}
@@ -191,14 +150,12 @@ public class SuggestHelper {
boolean isUserBigramSuggestion(CharSequence previous, char typed,
CharSequence expected) {
- WordComposer word = createWordComposer(Character.toString(typed));
-
if (mUserBigram == null) return false;
flushUserBigrams();
if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) {
WordComposer firstChar = createWordComposer(Character.toString(typed));
- mSuggest.getSuggestions(null, firstChar, false, previous);
+ mSuggest.getSuggestions(null, firstChar, previous);
boolean reloading = mUserBigram.reloadDictionaryIfRequired();
if (reloading) mUserBigram.waitForDictionaryLoading();
mUserBigram.getBigrams(firstChar, previous, mSuggest, null);