mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
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
@ -34,17 +34,17 @@ public class AutoCorrection {
|
||||
|
||||
public static CharSequence computeAutoCorrectionWord(
|
||||
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 whitelistedWord) {
|
||||
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
||||
return whitelistedWord;
|
||||
} else if (hasAutoCorrectionForConsideredWord(
|
||||
dictionaries, wordComposer, suggestions, consideredWord)) {
|
||||
dictionaries, wordComposer, suggestion, consideredWord)) {
|
||||
return consideredWord;
|
||||
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions,
|
||||
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestion,
|
||||
consideredWord, autoCorrectionThreshold)) {
|
||||
return suggestions.get(0).mWord;
|
||||
return suggestion.mWord;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -111,27 +111,26 @@ public class AutoCorrection {
|
||||
|
||||
private static boolean hasAutoCorrectionForConsideredWord(
|
||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
|
||||
final WordComposer wordComposer, final SuggestedWordInfo suggestion,
|
||||
final CharSequence consideredWord) {
|
||||
if (TextUtils.isEmpty(consideredWord)) return false;
|
||||
return wordComposer.size() > 1 && suggestions.size() > 0
|
||||
return wordComposer.size() > 1 && null != suggestion
|
||||
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
||||
}
|
||||
|
||||
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
|
||||
ArrayList<SuggestedWordInfo> suggestions,
|
||||
SuggestedWordInfo suggestion,
|
||||
CharSequence consideredWord, float autoCorrectionThreshold) {
|
||||
if (wordComposer.size() > 1 && suggestions.size() > 0) {
|
||||
final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0);
|
||||
if (wordComposer.size() > 1 && null != suggestion) {
|
||||
//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
|
||||
// the normalized score of the second suggestion, behave less aggressive.
|
||||
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
|
||||
consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(),
|
||||
consideredWord.toString(), suggestion.mWord.toString(),
|
||||
autoCorrectionSuggestionScore);
|
||||
if (DBG) {
|
||||
Log.d(TAG, "Normalized " + consideredWord + "," + autoCorrectionSuggestion + ","
|
||||
Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + ","
|
||||
+ autoCorrectionSuggestionScore + ", " + normalizedScore
|
||||
+ "(" + autoCorrectionThreshold + ")");
|
||||
}
|
||||
|
@ -249,6 +249,8 @@ public class Suggest {
|
||||
transformedWordInfo.mSourceDict);
|
||||
}
|
||||
|
||||
final SuggestedWordInfo bestSuggestion = suggestionsContainer.isEmpty()
|
||||
? null : suggestionsContainer.get(0);
|
||||
final CharSequence whitelistedWord = capitalizeWord(isAllUpperCase,
|
||||
isFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord));
|
||||
|
||||
@ -256,7 +258,7 @@ public class Suggest {
|
||||
if (isCorrectionEnabled) {
|
||||
final CharSequence autoCorrection =
|
||||
AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer,
|
||||
suggestionsContainer, consideredWord, mAutoCorrectionThreshold,
|
||||
bestSuggestion, consideredWord, mAutoCorrectionThreshold,
|
||||
whitelistedWord);
|
||||
hasAutoCorrection = (null != autoCorrection);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user