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_shift_key_timeout">1200</integer>
<integer name="config_multi_tap_key_timeout">800</integer>
<string-array name="auto_complete_threshold_values">
<!-- Off, When auto completing setting is Off, this value is not used. -->
<string-array name="auto_correction_threshold_values">
<!-- Off, When auto correction setting is Off, this value is not used. -->
<item></item>
<!-- 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>
<!-- 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>
</string-array>
</resources>

View File

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

View File

@ -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"
/>
<CheckBoxPreference

View File

@ -1438,8 +1438,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mCandidateView != null) {
mCandidateView.setSuggestions(words);
if (mCandidateView.isConfigCandidateHighlightFontColorEnabled())
mKeyboardSwitcher.onAutoCorrectionStateChanged(words.hasAutoCorrectionWord());
if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) {
mKeyboardSwitcher.onAutoCorrectionStateChanged(
words.hasWordAboveAutoCorrectionScoreThreshold());
}
}
}
@ -1460,8 +1462,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private SuggestedWords.Builder getTypedSuggestions(WordComposer word) {
return mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getInputView(), word, false, null);
return mSuggest.getSuggestedWordBuilder(mKeyboardSwitcher.getInputView(), word, null);
}
private void showCorrections(WordAlternatives alternatives) {
@ -1477,9 +1478,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getInputView(), word, false, prevWord);
// long stopTime = System.currentTimeMillis(); // TIME MEASUREMENT!
// Log.d("LatinIME","Suggest Total Time - " + (stopTime - startTime));
mKeyboardSwitcher.getInputView(), word, prevWord);
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
@ -1506,8 +1505,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
setSuggestions(suggestedWords);
if (suggestedWords.size() > 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);
}

View File

@ -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));
}

View File

@ -95,7 +95,6 @@ public class Suggest implements Dictionary.WordCallback {
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
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;

View File

@ -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 {

View File

@ -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);