Optimization & Simplification
It's useless to do the whitelist lookup twice. Also, putting this test out of this method will allow whitelist entries to come from other sources. Bug: 6906525 Change-Id: I4afe678cae6556d16642d155ce770fbf4e61ad49main
parent
dc2fb6bc6d
commit
caed149b67
|
@ -75,17 +75,10 @@ public class AutoCorrection {
|
||||||
return maxFreq;
|
return maxFreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if this is a whitelist entry, or it isn't in any dictionary.
|
// Returns true if this isn't in any dictionary.
|
||||||
public static boolean isWhitelistedOrNotAWord(
|
public static boolean isNotAWord(
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
final CharSequence word, final boolean ignoreCase) {
|
final CharSequence word, final boolean ignoreCase) {
|
||||||
final WhitelistDictionary whitelistDictionary =
|
|
||||||
(WhitelistDictionary)dictionaries.get(Dictionary.TYPE_WHITELIST);
|
|
||||||
// If "word" is in the whitelist dictionary, it should not be auto corrected.
|
|
||||||
if (whitelistDictionary != null
|
|
||||||
&& whitelistDictionary.shouldForciblyAutoCorrectFrom(word)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return !isValidWord(dictionaries, word, ignoreCase);
|
return !isValidWord(dictionaries, word, ignoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,14 +208,6 @@ public class Suggest {
|
||||||
wordComposerForLookup, prevWordForBigram, proximityInfo));
|
wordComposerForLookup, prevWordForBigram, proximityInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
|
|
||||||
// but still autocorrected from - in the case the whitelist only capitalizes the word.
|
|
||||||
// The whitelist should be case-insensitive, so it's not possible to be consistent with
|
|
||||||
// a boolean flag. Right now this is handled with a slight hack in
|
|
||||||
// WhitelistDictionary#shouldForciblyAutoCorrectFrom.
|
|
||||||
final boolean allowsToBeAutoCorrected = AutoCorrection.isWhitelistedOrNotAWord(
|
|
||||||
mDictionaries, consideredWord, wordComposer.isFirstCharCapitalized());
|
|
||||||
|
|
||||||
final CharSequence whitelistedWord =
|
final CharSequence whitelistedWord =
|
||||||
mWhiteListDictionary.getWhitelistedWord(consideredWord);
|
mWhiteListDictionary.getWhitelistedWord(consideredWord);
|
||||||
if (whitelistedWord != null) {
|
if (whitelistedWord != null) {
|
||||||
|
@ -225,6 +217,16 @@ public class Suggest {
|
||||||
Dictionary.TYPE_WHITELIST));
|
Dictionary.TYPE_WHITELIST));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
|
||||||
|
// but still autocorrected from - in the case the whitelist only capitalizes the word.
|
||||||
|
// The whitelist should be case-insensitive, so it's not possible to be consistent with
|
||||||
|
// a boolean flag. Right now this is handled with a slight hack in
|
||||||
|
// WhitelistDictionary#shouldForciblyAutoCorrectFrom.
|
||||||
|
final boolean allowsToBeAutoCorrected = (null != whitelistedWord
|
||||||
|
&& !whitelistedWord.equals(consideredWord))
|
||||||
|
|| AutoCorrection.isNotAWord(mDictionaries, consideredWord,
|
||||||
|
wordComposer.isFirstCharCapitalized());
|
||||||
|
|
||||||
final boolean hasAutoCorrection;
|
final boolean hasAutoCorrection;
|
||||||
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
|
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
|
||||||
// any attempt to do auto-correction is already shielded with a test for this flag; at the
|
// any attempt to do auto-correction is already shielded with a test for this flag; at the
|
||||||
|
|
Loading…
Reference in New Issue