am 58eed636: Merge "Stop considering personalization dicts outputs as words"

* commit '58eed6360db7f8d2ba12ab34d18656f8ec7b6116':
  Stop considering personalization dicts outputs as words
main
Jean Chalard 2014-02-05 05:37:23 -08:00 committed by Android Git Automerger
commit ba8a44b3bb
5 changed files with 31 additions and 7 deletions

View File

@ -750,7 +750,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// TODO: Implement BinaryDictionary.isInDictionary(). // TODO: Implement BinaryDictionary.isInDictionary().
@UsedForTesting @UsedForTesting
public boolean isInDictionaryForTests(final String word) { public boolean isInUnderlyingBinaryDictionaryForTests(final String word) {
final AsyncResultHolder<Boolean> holder = new AsyncResultHolder<Boolean>(); final AsyncResultHolder<Boolean> holder = new AsyncResultHolder<Boolean>();
getExecutor(mDictName).executePrioritized(new Runnable() { getExecutor(mDictName).executePrioritized(new Runnable() {
@Override @Override

View File

@ -127,21 +127,33 @@ public final class Suggest {
mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram, mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram,
proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING, proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING,
suggestionsSet); suggestionsSet);
final String firstSuggestion;
final String whitelistedWord; final String whitelistedWord;
if (suggestionsSet.isEmpty()) { if (suggestionsSet.isEmpty()) {
whitelistedWord = null; whitelistedWord = firstSuggestion = null;
} else if (SuggestedWordInfo.KIND_WHITELIST != suggestionsSet.first().mKind) {
whitelistedWord = null;
} else { } else {
whitelistedWord = suggestionsSet.first().mWord; final SuggestedWordInfo firstSuggestedWordInfo = suggestionsSet.first();
firstSuggestion = firstSuggestedWordInfo.mWord;
if (SuggestedWordInfo.KIND_WHITELIST != firstSuggestedWordInfo.mKind) {
whitelistedWord = null;
} else {
whitelistedWord = firstSuggestion;
}
} }
// The word can be auto-corrected if it has a whitelist entry that is not itself, // The word can be auto-corrected if it has a whitelist entry that is not itself,
// or if it's a 2+ characters non-word (i.e. it's not in the dictionary). // or if it's a 2+ characters non-word (i.e. it's not in the dictionary).
// We allow auto-correction if we have a whitelisted word, or if the word is not a valid
// word of more than 1 char, except if the first suggestion is the same as the typed string
// because in this case if it's strong enough to auto-correct that will mistakenly designate
// the second candidate for auto-correction.
// TODO: stop relying on indices to find where is the auto-correction in the suggested
// words, and correct this test.
final boolean allowsToBeAutoCorrected = (null != whitelistedWord final boolean allowsToBeAutoCorrected = (null != whitelistedWord
&& !whitelistedWord.equals(consideredWord)) && !whitelistedWord.equals(consideredWord))
|| (consideredWord.length() > 1 && !mDictionaryFacilitator.isValidWord( || (consideredWord.length() > 1 && !mDictionaryFacilitator.isValidWord(
consideredWord, wordComposer.isFirstCharCapitalized())); consideredWord, wordComposer.isFirstCharCapitalized())
&& !consideredWord.equals(firstSuggestion));
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

View File

@ -39,4 +39,10 @@ public class PersonalizationDictionary extends DecayingExpandableBinaryDictionar
super(context, locale, Dictionary.TYPE_PERSONALIZATION, getDictNameWithLocale(NAME, locale), super(context, locale, Dictionary.TYPE_PERSONALIZATION, getDictNameWithLocale(NAME, locale),
dictFile); dictFile);
} }
@Override
public boolean isValidWord(final String word) {
// Strings out of this dictionary should not be considered existing words.
return false;
}
} }

View File

@ -45,4 +45,10 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
public void cancelAddingUserHistory(final String word0, final String word1) { public void cancelAddingUserHistory(final String word0, final String word1) {
removeBigramDynamically(word0, word1); removeBigramDynamically(word0, word1);
} }
@Override
public boolean isValidWord(final String word) {
// Strings out of this dictionary should not be considered existing words.
return false;
}
} }

View File

@ -90,7 +90,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
dict.waitAllTasksForTests(); dict.waitAllTasksForTests();
for (int i = 0; i < numberOfWords; ++i) { for (int i = 0; i < numberOfWords; ++i) {
final String word = words.get(i); final String word = words.get(i);
assertTrue(dict.isInDictionaryForTests(word)); assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
} }
} }
// write to file. // write to file.