Fix auto correction threshold values array reference

This change also removes unused argument from Suggest.getSuggestions().

Change-Id: I512f8695d22898bb906e136a66e0ee6b521cd1d1
main
Tadashi G. Takaoka 2010-12-13 12:37:23 +09:00
parent 4ca16dbd65
commit 9ecad8c2e8
8 changed files with 52 additions and 52 deletions

View File

@ -32,14 +32,14 @@
<integer name="config_long_press_key_timeout">400</integer> <integer name="config_long_press_key_timeout">400</integer>
<integer name="config_long_press_shift_key_timeout">1200</integer> <integer name="config_long_press_shift_key_timeout">1200</integer>
<integer name="config_multi_tap_key_timeout">800</integer> <integer name="config_multi_tap_key_timeout">800</integer>
<string-array name="auto_complete_threshold_values"> <string-array name="auto_correction_threshold_values">
<!-- Off, When auto completing setting is Off, this value is not used. --> <!-- Off, When auto correction setting is Off, this value is not used. -->
<item></item> <item></item>
<!-- Modest : Suggestion whose normalized score is greater than this value <!-- Modest : Suggestion whose normalized score is greater than this value
will be subject to auto-completion. --> will be subject to auto-correction. -->
<item>0.22</item> <item>0.22</item>
<!-- Aggressive : Suggestion whose normalized score is greater than this value <!-- Aggressive : Suggestion whose normalized score is greater than this value
will be subject to auto-completion. --> will be subject to auto-correction. -->
<item>0</item> <item>0</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -65,13 +65,13 @@
<item>@string/prefs_suggestion_visibility_hide_name</item> <item>@string/prefs_suggestion_visibility_hide_name</item>
</string-array> </string-array>
<string name="auto_correction_threshold_mode_value_off">0</string> <string name="auto_correction_threshold_mode_index_off">0</string>
<string name="auto_correction_threshold_mode_value_modest">1</string> <string name="auto_correction_threshold_mode_index_modest">1</string>
<string name="auto_correction_threshold_mode_value_aggeressive">2</string> <string name="auto_correction_threshold_mode_index_aggeressive">2</string>
<string-array name="auto_correction_threshold_mode_values"> <string-array name="auto_correction_threshold_mode_indexes">
<item>@string/auto_correction_threshold_mode_value_off</item> <item>@string/auto_correction_threshold_mode_index_off</item>
<item>@string/auto_correction_threshold_mode_value_modest</item> <item>@string/auto_correction_threshold_mode_index_modest</item>
<item>@string/auto_correction_threshold_mode_value_aggeressive</item> <item>@string/auto_correction_threshold_mode_index_aggeressive</item>
</string-array> </string-array>
<string-array name="auto_correction_threshold_modes"> <string-array name="auto_correction_threshold_modes">
<item>@string/auto_correction_threshold_mode_off</item> <item>@string/auto_correction_threshold_mode_off</item>

View File

@ -106,9 +106,9 @@
android:title="@string/auto_correction" android:title="@string/auto_correction"
android:summary="@string/auto_correction_summary" android:summary="@string/auto_correction_summary"
android:persistent="true" 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:entries="@array/auto_correction_threshold_modes"
android:defaultValue="@string/auto_correction_threshold_mode_value_modest" android:defaultValue="@string/auto_correction_threshold_mode_index_modest"
/> />
<CheckBoxPreference <CheckBoxPreference

View File

@ -1438,8 +1438,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mCandidateView != null) { if (mCandidateView != null) {
mCandidateView.setSuggestions(words); mCandidateView.setSuggestions(words);
if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) {
mKeyboardSwitcher.onAutoCorrectionStateChanged(words.hasAutoCorrectionWord()); mKeyboardSwitcher.onAutoCorrectionStateChanged(
words.hasWordAboveAutoCorrectionScoreThreshold());
}
} }
} }
@ -1460,8 +1462,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
private SuggestedWords.Builder getTypedSuggestions(WordComposer word) { private SuggestedWords.Builder getTypedSuggestions(WordComposer word) {
return mSuggest.getSuggestedWordBuilder( return mSuggest.getSuggestedWordBuilder(mKeyboardSwitcher.getInputView(), word, null);
mKeyboardSwitcher.getInputView(), word, false, null);
} }
private void showCorrections(WordAlternatives alternatives) { private void showCorrections(WordAlternatives alternatives) {
@ -1477,9 +1478,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(), CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
mWordSeparators); mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getInputView(), word, false, prevWord); mKeyboardSwitcher.getInputView(), word, prevWord);
// long stopTime = System.currentTimeMillis(); // TIME MEASUREMENT!
// Log.d("LatinIME","Suggest Total Time - " + (stopTime - startTime));
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies(); int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies); mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
@ -1506,8 +1505,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
setSuggestions(suggestedWords); setSuggestions(suggestedWords);
if (suggestedWords.size() > 0) { if (suggestedWords.size() > 0) {
if (suggestedWords.mHasMinimalSuggestion if (suggestedWords.hasAutoCorrectionWord()) {
&& !suggestedWords.mTypedWordValid && suggestedWords.size() > 1) {
mBestWord = suggestedWords.getWord(1); mBestWord = suggestedWords.getWord(1);
} else { } else {
mBestWord = typedWord; mBestWord = typedWord;
@ -2067,9 +2065,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final String currentAutoCorrectionSetting = sp.getString( final String currentAutoCorrectionSetting = sp.getString(
Settings.PREF_AUTO_CORRECTION_THRESHOLD, 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( 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. // When autoCrrectionThreshold is greater than 1.0, auto correction is virtually turned off.
double autoCorrectionThreshold = Double.MAX_VALUE; double autoCorrectionThreshold = Double.MAX_VALUE;
try { try {
@ -2094,9 +2092,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private boolean isAutoCorrectEnabled(SharedPreferences sp) { private boolean isAutoCorrectEnabled(SharedPreferences sp) {
final String currentAutoCorrectionSetting = sp.getString( final String currentAutoCorrectionSetting = sp.getString(
Settings.PREF_AUTO_CORRECTION_THRESHOLD, 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( 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); return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
} }

View File

@ -79,7 +79,7 @@ public class Settings extends PreferenceActivity
private void ensureConsistencyOfAutoCorrectionSettings() { private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString( 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(); final String currentSetting = mAutoCorrectionThreshold.getValue();
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff)); mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff));
} }

View File

@ -95,7 +95,6 @@ public class Suggest implements Dictionary.WordCallback {
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>(); ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>(); private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
private boolean mHaveCorrection; private boolean mHaveCorrection;
private CharSequence mOriginalWord;
private String mLowerOriginalWord; private String mLowerOriginalWord;
// TODO: Remove these member variables by passing more context to addWord() callback method // 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. * @return suggested words object.
*/ */
public SuggestedWords getSuggestions(View view, WordComposer wordComposer, public SuggestedWords getSuggestions(View view, WordComposer wordComposer,
boolean includeTypedWordIfValid, CharSequence prevWordForBigram) { CharSequence prevWordForBigram) {
return getSuggestedWordBuilder(view, wordComposer, includeTypedWordIfValid, return getSuggestedWordBuilder(view, wordComposer, prevWordForBigram).build();
prevWordForBigram).build();
} }
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer, public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
boolean includeTypedWordIfValid, CharSequence prevWordForBigram) { CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
mHaveCorrection = false; mHaveCorrection = false;
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
@ -214,13 +212,13 @@ public class Suggest implements Dictionary.WordCallback {
Arrays.fill(mNextLettersFrequencies, 0); Arrays.fill(mNextLettersFrequencies, 0);
// Save a lowercase version of the original word // Save a lowercase version of the original word
mOriginalWord = wordComposer.getTypedWord(); CharSequence typedWord = wordComposer.getTypedWord();
if (mOriginalWord != null) { if (typedWord != null) {
final String mOriginalWordString = mOriginalWord.toString(); final String typedWordString = typedWord.toString();
mOriginalWord = mOriginalWordString; typedWord = typedWordString;
mLowerOriginalWord = mOriginalWordString.toLowerCase(); mLowerOriginalWord = typedWordString.toLowerCase();
// Treating USER_TYPED as UNIGRAM suggestion for logging now. // 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); Dictionary.DataType.UNIGRAM);
} else { } else {
mLowerOriginalWord = ""; mLowerOriginalWord = "";
@ -278,7 +276,7 @@ public class Suggest implements Dictionary.WordCallback {
mContactsDictionary.getWords(wordComposer, this, mNextLettersFrequencies); mContactsDictionary.getWords(wordComposer, this, mNextLettersFrequencies);
} }
if (mSuggestions.size() > 0 && isValidWord(mOriginalWord) if (mSuggestions.size() > 0 && isValidWord(typedWord)
&& (mCorrectionMode == CORRECTION_FULL && (mCorrectionMode == CORRECTION_FULL
|| mCorrectionMode == CORRECTION_FULL_BIGRAM)) { || mCorrectionMode == CORRECTION_FULL_BIGRAM)) {
mHaveCorrection = true; 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 // TODO: when the normalized score of the first suggestion is nearly equals to
// the normalized score of the second suggestion, behave less aggressive. // the normalized score of the second suggestion, behave less aggressive.
final double normalizedScore = Utils.calcNormalizedScore( final double normalizedScore = Utils.calcNormalizedScore(
mOriginalWord, mSuggestions.get(0), mPriorities[0]); typedWord, mSuggestions.get(0), mPriorities[0]);
if (LatinImeLogger.sDBG) { if (LatinImeLogger.sDBG) {
Log.d(TAG, "Normalized " + mOriginalWord + "," + mSuggestions.get(0) + "," Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + ","
+ mPriorities[0] + normalizedScore + mPriorities[0] + normalizedScore
+ "(" + mAutoCorrectionThreshold + ")"); + "(" + mAutoCorrectionThreshold + ")");
} }
@ -301,8 +299,8 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
} }
if (mOriginalWord != null) { if (typedWord != null) {
mSuggestions.add(0, mOriginalWord.toString()); mSuggestions.add(0, typedWord.toString());
} }
if (mAutoTextEnabled) { if (mAutoTextEnabled) {
int i = 0; int i = 0;

View File

@ -53,7 +53,11 @@ public class SuggestedWords {
} }
public boolean hasAutoCorrectionWord() { 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 { public static class Builder {

View File

@ -125,19 +125,19 @@ public class SuggestHelper {
boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) { boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, null); SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
return isDefaultSuggestion(suggestions, expected); return isDefaultSuggestion(suggestions, expected);
} }
boolean isDefaultCorrection(CharSequence typed, CharSequence expected) { boolean isDefaultCorrection(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed); 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(); return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
} }
boolean isASuggestion(CharSequence typed, CharSequence expected) { boolean isASuggestion(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed); 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++) { for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected)) return true; if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
} }
@ -147,7 +147,7 @@ public class SuggestHelper {
private void getBigramSuggestions(CharSequence previous, CharSequence typed) { private void getBigramSuggestions(CharSequence previous, CharSequence typed) {
if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) { if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) {
WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0))); 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) { CharSequence expected) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed); getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous); SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
return isDefaultSuggestion(suggestions, expected); return isDefaultSuggestion(suggestions, expected);
} }
@ -163,7 +163,7 @@ public class SuggestHelper {
CharSequence expected) { CharSequence expected) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, 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(); return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
} }
@ -171,7 +171,7 @@ public class SuggestHelper {
CharSequence expected) { CharSequence expected) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, 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++) { for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected)) return true; if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
} }
@ -189,7 +189,7 @@ public class SuggestHelper {
flushUserBigrams(); flushUserBigrams();
if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) { if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) {
WordComposer firstChar = createWordComposer(Character.toString(typed)); WordComposer firstChar = createWordComposer(Character.toString(typed));
mSuggest.getSuggestions(null, firstChar, false, previous); mSuggest.getSuggestions(null, firstChar, previous);
boolean reloading = mUserBigram.reloadDictionaryIfRequired(); boolean reloading = mUserBigram.reloadDictionaryIfRequired();
if (reloading) mUserBigram.waitForDictionaryLoading(); if (reloading) mUserBigram.waitForDictionaryLoading();
mUserBigram.getBigrams(firstChar, previous, mSuggest, null); mUserBigram.getBigrams(firstChar, previous, mSuggest, null);