From 9ecad8c2e8571ece6f3f7fbb19ceda5be7866cf0 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 13 Dec 2010 12:37:23 +0900 Subject: [PATCH] Fix auto correction threshold values array reference This change also removes unused argument from Suggest.getSuggestions(). Change-Id: I512f8695d22898bb906e136a66e0ee6b521cd1d1 --- java/res/values/config.xml | 8 ++--- java/res/values/donottranslate.xml | 14 ++++----- java/res/xml/prefs.xml | 4 +-- .../android/inputmethod/latin/LatinIME.java | 24 +++++++-------- .../android/inputmethod/latin/Settings.java | 2 +- .../android/inputmethod/latin/Suggest.java | 30 +++++++++---------- .../inputmethod/latin/SuggestedWords.java | 6 +++- .../inputmethod/latin/SuggestHelper.java | 16 +++++----- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 456d9ad4d..0bb0e337d 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -32,14 +32,14 @@ 400 1200 800 - - + + + will be subject to auto-correction. --> 0.22 + will be subject to auto-correction. --> 0 diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index cfca4d624..57037290a 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -65,13 +65,13 @@ @string/prefs_suggestion_visibility_hide_name - 0 - 1 - 2 - - @string/auto_correction_threshold_mode_value_off - @string/auto_correction_threshold_mode_value_modest - @string/auto_correction_threshold_mode_value_aggeressive + 0 + 1 + 2 + + @string/auto_correction_threshold_mode_index_off + @string/auto_correction_threshold_mode_index_modest + @string/auto_correction_threshold_mode_index_aggeressive @string/auto_correction_threshold_mode_off diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 1bc33950d..0eee06031 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -106,9 +106,9 @@ android:title="@string/auto_correction" android:summary="@string/auto_correction_summary" android:persistent="true" - android:entryValues="@array/auto_correction_threshold_mode_values" + android:entryValues="@array/auto_correction_threshold_mode_indexes" android:entries="@array/auto_correction_threshold_modes" - android:defaultValue="@string/auto_correction_threshold_mode_value_modest" + android:defaultValue="@string/auto_correction_threshold_mode_index_modest" /> 0) { - if (suggestedWords.mHasMinimalSuggestion - && !suggestedWords.mTypedWordValid && suggestedWords.size() > 1) { + if (suggestedWords.hasAutoCorrectionWord()) { mBestWord = suggestedWords.getWord(1); } else { mBestWord = typedWord; @@ -2067,9 +2065,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final String currentAutoCorrectionSetting = sp.getString( Settings.PREF_AUTO_CORRECTION_THRESHOLD, - mResources.getString(R.string.auto_correction_threshold_mode_value_modest)); + mResources.getString(R.string.auto_correction_threshold_mode_index_modest)); final String[] autoCorrectionThresholdValues = mResources.getStringArray( - R.array.auto_correction_threshold_mode_values); + R.array.auto_correction_threshold_values); // When autoCrrectionThreshold is greater than 1.0, auto correction is virtually turned off. double autoCorrectionThreshold = Double.MAX_VALUE; try { @@ -2094,9 +2092,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean isAutoCorrectEnabled(SharedPreferences sp) { final String currentAutoCorrectionSetting = sp.getString( Settings.PREF_AUTO_CORRECTION_THRESHOLD, - mResources.getString(R.string.auto_correction_threshold_mode_value_modest)); + mResources.getString(R.string.auto_correction_threshold_mode_index_modest)); final String autoCorrectionOff = mResources.getString( - R.string.auto_correction_threshold_mode_value_off); + R.string.auto_correction_threshold_mode_index_off); return !currentAutoCorrectionSetting.equals(autoCorrectionOff); } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index d2ec917d0..b8590a76e 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -79,7 +79,7 @@ public class Settings extends PreferenceActivity private void ensureConsistencyOfAutoCorrectionSettings() { final String autoCorrectionOff = getResources().getString( - R.string.auto_correction_threshold_mode_value_off); + R.string.auto_correction_threshold_mode_index_off); final String currentSetting = mAutoCorrectionThreshold.getValue(); mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff)); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 77e0a3dde..a30ec1587 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -95,7 +95,6 @@ public class Suggest implements Dictionary.WordCallback { ArrayList mBigramSuggestions = new ArrayList(); private ArrayList mStringPool = new ArrayList(); private boolean mHaveCorrection; - private CharSequence mOriginalWord; private String mLowerOriginalWord; // TODO: Remove these member variables by passing more context to addWord() callback method @@ -197,14 +196,13 @@ public class Suggest implements Dictionary.WordCallback { * @return suggested words object. */ public SuggestedWords getSuggestions(View view, WordComposer wordComposer, - boolean includeTypedWordIfValid, CharSequence prevWordForBigram) { - return getSuggestedWordBuilder(view, wordComposer, includeTypedWordIfValid, - prevWordForBigram).build(); + CharSequence prevWordForBigram) { + return getSuggestedWordBuilder(view, wordComposer, prevWordForBigram).build(); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer, - boolean includeTypedWordIfValid, CharSequence prevWordForBigram) { + CharSequence prevWordForBigram) { LatinImeLogger.onStartSuggestion(prevWordForBigram); mHaveCorrection = false; mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); @@ -214,13 +212,13 @@ public class Suggest implements Dictionary.WordCallback { Arrays.fill(mNextLettersFrequencies, 0); // Save a lowercase version of the original word - mOriginalWord = wordComposer.getTypedWord(); - if (mOriginalWord != null) { - final String mOriginalWordString = mOriginalWord.toString(); - mOriginalWord = mOriginalWordString; - mLowerOriginalWord = mOriginalWordString.toLowerCase(); + CharSequence typedWord = wordComposer.getTypedWord(); + if (typedWord != null) { + final String typedWordString = typedWord.toString(); + typedWord = typedWordString; + mLowerOriginalWord = typedWordString.toLowerCase(); // Treating USER_TYPED as UNIGRAM suggestion for logging now. - LatinImeLogger.onAddSuggestedWord(mOriginalWordString, Suggest.DIC_USER_TYPED, + LatinImeLogger.onAddSuggestedWord(typedWordString, Suggest.DIC_USER_TYPED, Dictionary.DataType.UNIGRAM); } else { mLowerOriginalWord = ""; @@ -278,7 +276,7 @@ public class Suggest implements Dictionary.WordCallback { mContactsDictionary.getWords(wordComposer, this, mNextLettersFrequencies); } - if (mSuggestions.size() > 0 && isValidWord(mOriginalWord) + if (mSuggestions.size() > 0 && isValidWord(typedWord) && (mCorrectionMode == CORRECTION_FULL || mCorrectionMode == CORRECTION_FULL_BIGRAM)) { mHaveCorrection = true; @@ -290,9 +288,9 @@ public class Suggest implements Dictionary.WordCallback { // TODO: when the normalized score of the first suggestion is nearly equals to // the normalized score of the second suggestion, behave less aggressive. final double normalizedScore = Utils.calcNormalizedScore( - mOriginalWord, mSuggestions.get(0), mPriorities[0]); + typedWord, mSuggestions.get(0), mPriorities[0]); if (LatinImeLogger.sDBG) { - Log.d(TAG, "Normalized " + mOriginalWord + "," + mSuggestions.get(0) + "," + Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + "," + mPriorities[0] + normalizedScore + "(" + mAutoCorrectionThreshold + ")"); } @@ -301,8 +299,8 @@ public class Suggest implements Dictionary.WordCallback { } } } - if (mOriginalWord != null) { - mSuggestions.add(0, mOriginalWord.toString()); + if (typedWord != null) { + mSuggestions.add(0, typedWord.toString()); } if (mAutoTextEnabled) { int i = 0; diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 3a3176e54..0bb7c66d1 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -53,7 +53,11 @@ public class SuggestedWords { } public boolean hasAutoCorrectionWord() { - return mHasMinimalSuggestion && ((size() >= 1 && !mTypedWordValid) || mTypedWordValid); + return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid; + } + + public boolean hasWordAboveAutoCorrectionScoreThreshold() { + return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); } public static class Builder { diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java index 25ceef6b7..7254520d5 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java +++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java @@ -125,19 +125,19 @@ public class SuggestHelper { boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) { WordComposer word = createWordComposer(typed); - SuggestedWords 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); - SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, null); + SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null); return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection(); } boolean isASuggestion(CharSequence typed, CharSequence expected) { WordComposer word = createWordComposer(typed); - SuggestedWords 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.getWord(i), expected)) return true; } @@ -147,7 +147,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); } } @@ -155,7 +155,7 @@ public class SuggestHelper { CharSequence expected) { WordComposer word = createWordComposer(typed); getBigramSuggestions(previous, typed); - SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous); + SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous); return isDefaultSuggestion(suggestions, expected); } @@ -163,7 +163,7 @@ public class SuggestHelper { CharSequence expected) { WordComposer word = createWordComposer(typed); getBigramSuggestions(previous, typed); - SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous); + SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous); return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection(); } @@ -171,7 +171,7 @@ public class SuggestHelper { CharSequence expected) { WordComposer word = createWordComposer(typed); getBigramSuggestions(previous, typed); - SuggestedWords 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.getWord(i), expected)) return true; } @@ -189,7 +189,7 @@ public class SuggestHelper { 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);