Check isInDictionary() before the distracter test.

Bug: 13142176
Bug: 15428247
Change-Id: I7ce2c09ebbef6ca8c056807c2a35f2f987fd436e
main
Keisuke Kuroyanagi 2014-06-09 07:55:27 +09:00
parent 1910392eed
commit bdf745da32
5 changed files with 72 additions and 12 deletions

View File

@ -30,6 +30,7 @@ import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.DistracterFilter;
import com.android.inputmethod.latin.utils.DistracterFilterCheckingIsInDictionary;
import com.android.inputmethod.latin.utils.ExecutorUtils;
import com.android.inputmethod.latin.utils.LanguageModelParam;
import com.android.inputmethod.latin.utils.SuggestionResults;
@ -571,14 +572,15 @@ public class DictionaryFacilitator {
final PersonalizationDataChunk personalizationDataChunk,
final SpacingAndPunctuations spacingAndPunctuations,
final ExpandableBinaryDictionary.AddMultipleDictionaryEntriesCallback callback) {
final ExpandableBinaryDictionary personalizationDict =
mDictionaries.getSubDict(Dictionary.TYPE_PERSONALIZATION);
final ArrayList<LanguageModelParam> languageModelParams =
LanguageModelParam.createLanguageModelParamsFrom(
personalizationDataChunk.mTokens,
personalizationDataChunk.mTimestampInSeconds,
this /* dictionaryFacilitator */, spacingAndPunctuations,
mDistracterFilter);
final ExpandableBinaryDictionary personalizationDict =
mDictionaries.getSubDict(Dictionary.TYPE_PERSONALIZATION);
new DistracterFilterCheckingIsInDictionary(
mDistracterFilter, personalizationDict));
if (personalizationDict == null || languageModelParams == null
|| languageModelParams.isEmpty()) {
if (callback != null) {

View File

@ -81,7 +81,7 @@ import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.DialogUtils;
import com.android.inputmethod.latin.utils.DistracterFilterUsingSuggestion;
import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatches;
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import com.android.inputmethod.latin.utils.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils;
@ -121,7 +121,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final Settings mSettings;
private final DictionaryFacilitator mDictionaryFacilitator =
new DictionaryFacilitator(new DistracterFilterUsingSuggestion(this /* context */));
new DictionaryFacilitator(new DistracterFilterCheckingExactMatches(this /* context */));
private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
// We expect to have only one decoder in almost all cases, hence the default capacity of 1.

View File

@ -31,9 +31,8 @@ import com.android.inputmethod.latin.PrevWordsInfo;
* This class is used to prevent distracters being added to personalization
* or user history dictionaries
*/
// TODO: Rename.
public class DistracterFilterUsingSuggestion implements DistracterFilter {
private static final String TAG = DistracterFilterUsingSuggestion.class.getSimpleName();
public class DistracterFilterCheckingExactMatches implements DistracterFilter {
private static final String TAG = DistracterFilterCheckingExactMatches.class.getSimpleName();
private static final boolean DEBUG = false;
private static final long TIMEOUT_TO_WAIT_LOADING_DICTIONARIES_IN_SECONDS = 120;
@ -47,7 +46,7 @@ public class DistracterFilterUsingSuggestion implements DistracterFilter {
*
* @param context the context.
*/
public DistracterFilterUsingSuggestion(final Context context) {
public DistracterFilterCheckingExactMatches(final Context context) {
mContext = context;
mDictionaryFacilitator = new DictionaryFacilitator();
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.utils;
import java.util.List;
import java.util.Locale;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.PrevWordsInfo;
public class DistracterFilterCheckingIsInDictionary implements DistracterFilter {
private final DistracterFilter mDistracterFilter;
private final Dictionary mDictionary;
public DistracterFilterCheckingIsInDictionary(final DistracterFilter distracterFilter,
final Dictionary dictionary) {
mDistracterFilter = distracterFilter;
mDictionary = dictionary;
}
@Override
public boolean isDistracterToWordsInDictionaries(PrevWordsInfo prevWordsInfo,
String testedWord, Locale locale) {
if (mDictionary.isInDictionary(testedWord)) {
// This filter treats entries that are already in the dictionary as non-distracters
// because they have passed the filtering in the past.
return false;
} else {
return mDistracterFilter.isDistracterToWordsInDictionaries(
prevWordsInfo, testedWord, locale);
}
}
@Override
public void updateEnabledSubtypes(List<InputMethodSubtype> enabledSubtypes) {
// Do nothing.
}
@Override
public void close() {
// Do nothing.
}
}

View File

@ -20,19 +20,19 @@ import java.util.Locale;
import android.test.suitebuilder.annotation.LargeTest;
import com.android.inputmethod.latin.utils.DistracterFilterUsingSuggestion;
import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatches;
/**
* Unit test for DistracterFilter
*/
@LargeTest
public class DistracterFilterTest extends InputTestsBase {
private DistracterFilterUsingSuggestion mDistracterFilter;
private DistracterFilterCheckingExactMatches mDistracterFilter;
@Override
protected void setUp() throws Exception {
super.setUp();
mDistracterFilter = new DistracterFilterUsingSuggestion(getContext());
mDistracterFilter = new DistracterFilterCheckingExactMatches(getContext());
mDistracterFilter.updateEnabledSubtypes(mLatinIME.getEnabledSubtypesForTest());
}