Don't pass everything to a function that needs only the head (A2)
Change-Id: Ic367836202ab8071c1a9a02eaf0651b0da947d51
This commit is contained in:
parent
09b30ac954
commit
b7cdafd78a
2 changed files with 14 additions and 13 deletions
|
@ -34,17 +34,17 @@ public class AutoCorrection {
|
||||||
|
|
||||||
public static CharSequence computeAutoCorrectionWord(
|
public static CharSequence computeAutoCorrectionWord(
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
|
final WordComposer wordComposer, SuggestedWordInfo suggestion,
|
||||||
final CharSequence consideredWord, final float autoCorrectionThreshold,
|
final CharSequence consideredWord, final float autoCorrectionThreshold,
|
||||||
final CharSequence whitelistedWord) {
|
final CharSequence whitelistedWord) {
|
||||||
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
||||||
return whitelistedWord;
|
return whitelistedWord;
|
||||||
} else if (hasAutoCorrectionForConsideredWord(
|
} else if (hasAutoCorrectionForConsideredWord(
|
||||||
dictionaries, wordComposer, suggestions, consideredWord)) {
|
dictionaries, wordComposer, suggestion, consideredWord)) {
|
||||||
return consideredWord;
|
return consideredWord;
|
||||||
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions,
|
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestion,
|
||||||
consideredWord, autoCorrectionThreshold)) {
|
consideredWord, autoCorrectionThreshold)) {
|
||||||
return suggestions.get(0).mWord;
|
return suggestion.mWord;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -111,27 +111,26 @@ public class AutoCorrection {
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForConsideredWord(
|
private static boolean hasAutoCorrectionForConsideredWord(
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
|
final WordComposer wordComposer, final SuggestedWordInfo suggestion,
|
||||||
final CharSequence consideredWord) {
|
final CharSequence consideredWord) {
|
||||||
if (TextUtils.isEmpty(consideredWord)) return false;
|
if (TextUtils.isEmpty(consideredWord)) return false;
|
||||||
return wordComposer.size() > 1 && suggestions.size() > 0
|
return wordComposer.size() > 1 && null != suggestion
|
||||||
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
|
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
|
||||||
ArrayList<SuggestedWordInfo> suggestions,
|
SuggestedWordInfo suggestion,
|
||||||
CharSequence consideredWord, float autoCorrectionThreshold) {
|
CharSequence consideredWord, float autoCorrectionThreshold) {
|
||||||
if (wordComposer.size() > 1 && suggestions.size() > 0) {
|
if (wordComposer.size() > 1 && null != suggestion) {
|
||||||
final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0);
|
|
||||||
//final int autoCorrectionSuggestionScore = sortedScores[0];
|
//final int autoCorrectionSuggestionScore = sortedScores[0];
|
||||||
final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore;
|
final int autoCorrectionSuggestionScore = suggestion.mScore;
|
||||||
// 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 float normalizedScore = BinaryDictionary.calcNormalizedScore(
|
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
|
||||||
consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(),
|
consideredWord.toString(), suggestion.mWord.toString(),
|
||||||
autoCorrectionSuggestionScore);
|
autoCorrectionSuggestionScore);
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Normalized " + consideredWord + "," + autoCorrectionSuggestion + ","
|
Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + ","
|
||||||
+ autoCorrectionSuggestionScore + ", " + normalizedScore
|
+ autoCorrectionSuggestionScore + ", " + normalizedScore
|
||||||
+ "(" + autoCorrectionThreshold + ")");
|
+ "(" + autoCorrectionThreshold + ")");
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,6 +249,8 @@ public class Suggest {
|
||||||
transformedWordInfo.mSourceDict);
|
transformedWordInfo.mSourceDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final SuggestedWordInfo bestSuggestion = suggestionsContainer.isEmpty()
|
||||||
|
? null : suggestionsContainer.get(0);
|
||||||
final CharSequence whitelistedWord = capitalizeWord(isAllUpperCase,
|
final CharSequence whitelistedWord = capitalizeWord(isAllUpperCase,
|
||||||
isFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord));
|
isFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord));
|
||||||
|
|
||||||
|
@ -256,7 +258,7 @@ public class Suggest {
|
||||||
if (isCorrectionEnabled) {
|
if (isCorrectionEnabled) {
|
||||||
final CharSequence autoCorrection =
|
final CharSequence autoCorrection =
|
||||||
AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer,
|
AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer,
|
||||||
suggestionsContainer, consideredWord, mAutoCorrectionThreshold,
|
bestSuggestion, consideredWord, mAutoCorrectionThreshold,
|
||||||
whitelistedWord);
|
whitelistedWord);
|
||||||
hasAutoCorrection = (null != autoCorrection);
|
hasAutoCorrection = (null != autoCorrection);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue