From 281dd99346e2d45280143a22105a77ba91766703 Mon Sep 17 00:00:00 2001 From: Xiaojun Bi Date: Wed, 16 Apr 2014 09:24:08 -0700 Subject: [PATCH] Prepare to implement distracter filter It was implemented according to the Plan B in the design doc: http://go/ime-misspelling-filter This CL is to create a DistracterFilter instance and pass it to PersonalizationDictionarySessionRegistrar. This patch should be checked in together with Id633b4fd45693 Bug: 13142176 Change-Id: Ia4957e64218c9619fcf9bb91795a187617c72a2e --- .../DictionaryFacilitatorForSuggest.java | 1 - .../android/inputmethod/latin/LatinIME.java | 16 ++++++- ...onalizationDictionarySessionRegistrar.java | 7 ++- .../latin/utils/DistracterFilter.java | 48 +++++++++++++++++++ 4 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/utils/DistracterFilter.java diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index 331384fa5..be81ed3b3 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -536,7 +536,6 @@ public class DictionaryFacilitatorForSuggest { return maxFreq; } - public void clearUserHistoryDictionary() { final UserHistoryDictionary userHistoryDict = mDictionaries.mUserHistoryDictionary; if (userHistoryDict == null) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 81b02c396..971bd1a16 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -84,6 +84,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.DistracterFilter; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.JniUtils; @@ -540,6 +541,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen refreshPersonalizationDictionarySession(); } + private DistracterFilter createDistracterFilter() { + final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); + final Keyboard keyboard = mainKeyboardView.getKeyboard(); + final DistracterFilter distracterFilter = new DistracterFilter(mInputLogic.mSuggest, + keyboard); + return distracterFilter; + } + private void refreshPersonalizationDictionarySession() { final DictionaryFacilitatorForSuggest dictionaryFacilitator = mInputLogic.mSuggest.mDictionaryFacilitator; @@ -564,7 +573,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen PersonalizationHelper.removeAllPersonalizationDictionaries(this); PersonalizationDictionarySessionRegistrar.resetAll(this); } else { - PersonalizationDictionarySessionRegistrar.init(this, dictionaryFacilitator); + final DistracterFilter distracterFilter = createDistracterFilter(); + PersonalizationDictionarySessionRegistrar.init( + this, dictionaryFacilitator, distracterFilter); } } @@ -662,8 +673,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.mConnection.finishComposingText(); mInputLogic.mConnection.endBatchEdit(); } + final DistracterFilter distracterFilter = createDistracterFilter(); PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf, - mInputLogic.mSuggest.mDictionaryFacilitator); + mInputLogic.mSuggest.mDictionaryFacilitator, distracterFilter); super.onConfigurationChanged(conf); } diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java index d6c0dc0dc..9bef7a198 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationDictionarySessionRegistrar.java @@ -20,14 +20,17 @@ import android.content.Context; import android.content.res.Configuration; import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; +import com.android.inputmethod.latin.utils.DistracterFilter; public class PersonalizationDictionarySessionRegistrar { public static void init(final Context context, - final DictionaryFacilitatorForSuggest dictionaryFacilitator) { + final DictionaryFacilitatorForSuggest dictionaryFacilitator, + final DistracterFilter distracterFilter) { } public static void onConfigurationChanged(final Context context, final Configuration conf, - final DictionaryFacilitatorForSuggest dictionaryFacilitator) { + final DictionaryFacilitatorForSuggest dictionaryFacilitator, + final DistracterFilter distracterFilter) { } public static void onUpdateData(final Context context, final String type) { diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java new file mode 100644 index 000000000..f2a1e524d --- /dev/null +++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilter.java @@ -0,0 +1,48 @@ +/* + * 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 com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.Suggest; + +/** + * This class is used to prevent distracters/misspellings being added to personalization + * or user history dictionaries + */ +public class DistracterFilter { + private final Suggest mSuggest; + private final Keyboard mKeyboard; + + /** + * Create a DistracterFilter instance. + * + * @param suggest an instance of Suggest which will be used to obtain a list of suggestions + * for a potential distracter/misspelling + * @param keyboard the keyboard that is currently being used. This information is needed + * when calling mSuggest.getSuggestedWords(...) to obtain a list of suggestions. + */ + public DistracterFilter(final Suggest suggest, final Keyboard keyboard) { + mSuggest = suggest; + mKeyboard = keyboard; + } + + public boolean isDistractorToWordsInDictionaries(final String prevWord, + final String targetWord) { + // TODO: to be implemented + return false; + } +}