Merge "Stop filtering out when perfect freq > top non-perfect freq."

main
Keisuke Kuroyanagi 2014-05-27 07:14:15 +00:00 committed by Android (Google) Code Review
commit 6a546147eb
3 changed files with 44 additions and 5 deletions

View File

@ -408,7 +408,7 @@ public class DictionaryFacilitator {
if (userHistoryDictionary == null) {
return;
}
final int maxFreq = getMaxFrequency(word);
final int maxFreq = getFrequency(word);
if (maxFreq == 0 && blockPotentiallyOffensive) {
return;
}
@ -516,7 +516,7 @@ public class DictionaryFacilitator {
return false;
}
private int getMaxFrequency(final String word) {
public int getFrequency(final String word) {
if (TextUtils.isEmpty(word)) {
return Dictionary.NOT_A_PROBABILITY;
}

View File

@ -33,6 +33,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.PrevWordsInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
@ -98,10 +99,12 @@ public class DistracterFilterUsingSuggestion implements DistracterFilter {
}
}
private static boolean isDistracter(
private boolean isDistracter(
final SuggestionResults suggestionResults, final String consideredWord) {
int perfectMatchProbability = Dictionary.NOT_A_PROBABILITY;
for (final SuggestedWordInfo suggestedWordInfo : suggestionResults) {
if (suggestedWordInfo.mWord.equals(consideredWord)) {
perfectMatchProbability = mDictionaryFacilitator.getFrequency(consideredWord);
continue;
}
// Exact match can include case errors, accent errors, digraph conversions.
@ -121,6 +124,17 @@ public class DistracterFilterUsingSuggestion implements DistracterFilter {
Log.d(TAG, "isExactMatchWithIntentionalOmission: "
+ isExactMatchWithIntentionalOmission);
}
if (perfectMatchProbability != Dictionary.NOT_A_PROBABILITY) {
final int topNonPerfectProbability = mDictionaryFacilitator.getFrequency(
suggestedWordInfo.mWord);
if (DEBUG) {
Log.d(TAG, "perfectMatchProbability: " + perfectMatchProbability);
Log.d(TAG, "topNonPerfectProbability: " + topNonPerfectProbability);
}
if (perfectMatchProbability > topNonPerfectProbability) {
return false;
}
}
return isExactMatch || isExactMatchWithIntentionalOmission;
}
return false;

View File

@ -57,11 +57,36 @@ public class DistracterFilterTest extends InputTestsBase {
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "were";
// For this test case, we consider "were" is a distracter to "we're".
typedWord = "youre";
// For this test case, we consider "youre" is a distracter to "you're".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "Banana";
// For this test case, we consider "Banana" is a distracter to "banana".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "orange";
// For this test case, we consider "orange" is not a distracter to any word in dictionaries.
assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "Orange";
// For this test case, we consider "Orange" is a distracter to "orange".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "café";
// For this test case, we consider "café" is a distracter to "cafe".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "cafe";
// For this test case, we consider "café" is not a distracter to any word in dictionaries.
assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
typedWord = "ill";
// For this test case, we consider "ill" is not a distracter to any word in dictionaries.
assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(