Merge "Optimize and clean up (B2)"

main
Jean Chalard 2012-03-08 22:00:02 -08:00 committed by Android (Google) Code Review
commit 54392438c5
2 changed files with 18 additions and 16 deletions

View File

@ -32,14 +32,14 @@ public class AutoCorrection {
public static CharSequence computeAutoCorrectionWord(Map<String, Dictionary> dictionaries, public static CharSequence computeAutoCorrectionWord(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores, WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold, int correctionMode, CharSequence typedWord, double autoCorrectionThreshold,
CharSequence whitelistedWord) { CharSequence whitelistedWord) {
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) { if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
return whitelistedWord; return whitelistedWord;
} else if (hasAutoCorrectionForTypedWord( } else if (hasAutoCorrectionForTypedWord(
dictionaries, wordComposer, suggestions, typedWord, correctionMode)) { dictionaries, wordComposer, suggestions, typedWord)) {
return typedWord; return typedWord;
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, correctionMode, } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions,
sortedScores, typedWord, autoCorrectionThreshold)) { sortedScores, typedWord, autoCorrectionThreshold)) {
return suggestions.get(0); return suggestions.get(0);
} }
@ -88,20 +88,17 @@ public class AutoCorrection {
} }
private static boolean hasAutoCorrectionForTypedWord(Map<String, Dictionary> dictionaries, private static boolean hasAutoCorrectionForTypedWord(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions, CharSequence typedWord, WordComposer wordComposer, ArrayList<CharSequence> suggestions,
int correctionMode) { CharSequence typedWord) {
if (TextUtils.isEmpty(typedWord)) return false; if (TextUtils.isEmpty(typedWord)) return false;
return wordComposer.size() > 1 && suggestions.size() > 0 return wordComposer.size() > 1 && suggestions.size() > 0
&& !allowsToBeAutoCorrected(dictionaries, typedWord, false) && !allowsToBeAutoCorrected(dictionaries, typedWord, false);
&& (correctionMode == Suggest.CORRECTION_FULL
|| correctionMode == Suggest.CORRECTION_FULL_BIGRAM);
} }
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer, private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores, ArrayList<CharSequence> suggestions, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold) { CharSequence typedWord, double autoCorrectionThreshold) {
if (wordComposer.size() > 1 && (correctionMode == Suggest.CORRECTION_FULL if (wordComposer.size() > 1
|| correctionMode == Suggest.CORRECTION_FULL_BIGRAM)
&& typedWord != null && suggestions.size() > 0 && sortedScores.length > 0) { && typedWord != null && suggestions.size() > 0 && sortedScores.length > 0) {
final CharSequence autoCorrectionSuggestion = suggestions.get(0); final CharSequence autoCorrectionSuggestion = suggestions.get(0);
final int autoCorrectionSuggestionScore = sortedScores[0]; final int autoCorrectionSuggestionScore = sortedScores[0];

View File

@ -346,11 +346,16 @@ public class Suggest implements Dictionary.WordCallback {
CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized, CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized,
mWhiteListDictionary.getWhitelistedWord(consideredWordString)); mWhiteListDictionary.getWhitelistedWord(consideredWordString));
final CharSequence autoCorrection = if (CORRECTION_FULL == correctionMode
AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer, || CORRECTION_FULL_BIGRAM == correctionMode) {
mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, correctionMode, final CharSequence autoCorrection =
whitelistedWord); AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
mHasAutoCorrection = (null != autoCorrection); mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold,
whitelistedWord);
mHasAutoCorrection = (null != autoCorrection);
} else {
mHasAutoCorrection = false;
}
if (whitelistedWord != null) { if (whitelistedWord != null) {
if (mTrailingSingleQuotesCount > 0) { if (mTrailingSingleQuotesCount > 0) {