am 96013c96: Merge "Revert "Use dedicated DictionaryFacilitator for DistracterFilter""

* commit '96013c9605218bac83c614961b8e35608e9eca5d':
  Revert "Use dedicated DictionaryFacilitator for DistracterFilter"
main
Keisuke Kuroyanagi 2014-05-16 11:19:28 +00:00 committed by Android Git Automerger
commit 22df3f915c
4 changed files with 15 additions and 55 deletions

View File

@ -140,10 +140,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final SubtypeState mSubtypeState = new SubtypeState();
// Object for reacting to adding/removing a dictionary pack.
private final BroadcastReceiver mDictionaryPackInstallReceiver =
private BroadcastReceiver mDictionaryPackInstallReceiver =
new DictionaryPackInstallBroadcastReceiver(this);
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
private BroadcastReceiver mDictionaryDumpBroadcastReceiver =
new DictionaryDumpBroadcastReceiver(this);
private AlertDialog mOptionsDialog;
@ -1629,8 +1629,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// boolean onKeyMultiple(final int keyCode, final int count, final KeyEvent event);
// receive ringer mode change and network state change.
private final BroadcastReceiver mConnectivityAndRingerModeChangeReceiver =
new BroadcastReceiver() {
private BroadcastReceiver mConnectivityAndRingerModeChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction();
@ -1747,7 +1746,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@UsedForTesting
/* package for test */ DistracterFilter createDistracterFilter() {
return DistracterFilterUtils.createDistracterFilter(this /* Context */, mKeyboardSwitcher);
return DistracterFilterUtils.createDistracterFilter(
mInputLogic.mSuggest, mKeyboardSwitcher);
}
public void dumpDictionaryForDebug(final String dictName) {

View File

@ -16,17 +16,8 @@
package com.android.inputmethod.latin.utils;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import android.content.Context;
import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest.
DictionaryInitializationListener;
import com.android.inputmethod.latin.Suggest;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
import com.android.inputmethod.latin.SuggestedWords;
@ -38,11 +29,6 @@ import com.android.inputmethod.latin.WordComposer;
* or user history dictionaries
*/
public class DistracterFilter {
private static final String TAG = DistracterFilter.class.getSimpleName();
private static final long TIMEOUT_TO_WAIT_LOADING_DICTIONARIES_IN_SECONDS = 120;
private final Context mContext;
private final Suggest mSuggest;
private final Keyboard mKeyboard;
@ -56,13 +42,13 @@ public class DistracterFilter {
/**
* Create a DistracterFilter instance.
*
* @param context the context.
* @param suggest an instance of Suggest which will be used to obtain a list of suggestions
* for a potential distracter
* @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 Context context, final Keyboard keyboard) {
mContext = context;
mSuggest = new Suggest();
public DistracterFilter(final Suggest suggest, final Keyboard keyboard) {
mSuggest = suggest;
mKeyboard = keyboard;
}
@ -80,44 +66,19 @@ public class DistracterFilter {
return false;
}
private void loadDictionariesForLocale(final Locale newlocale) throws InterruptedException {
final CountDownLatch countdownLatch = new CountDownLatch(1 /* count */);
mSuggest.mDictionaryFacilitator.resetDictionaries(mContext, newlocale,
false /* useContactsDict */, false /* usePersonalizedDicts */,
false /* forceReloadMainDictionary */,
new DictionaryInitializationListener() {
@Override
public void onUpdateMainDictionaryAvailability(
boolean isMainDictionaryAvailable) {
countdownLatch.countDown();
}
});
countdownLatch.await(TIMEOUT_TO_WAIT_LOADING_DICTIONARIES_IN_SECONDS, TimeUnit.SECONDS);
}
/**
* Determine whether a word is a distracter to words in dictionaries.
*
* @param prevWord the previous word, or null if none.
* @param testedWord the word that will be tested to see whether it is a distracter to words
* in dictionaries.
* @param locale the locale of words.
* @return true if testedWord is a distracter, otherwise false.
*/
public boolean isDistracterToWordsInDictionaries(final String prevWord,
final String testedWord, final Locale locale) {
if (mKeyboard == null || locale == null) {
final String testedWord) {
if (mSuggest == null || mKeyboard == null) {
return false;
}
if (!locale.equals(mSuggest.mDictionaryFacilitator.getLocale())) {
// Reset dictionaries for the locale.
try {
loadDictionariesForLocale(locale);
} catch (final InterruptedException e) {
Log.e(TAG, "Interrupted while waiting for loading dicts in DistracterFilter", e);
return false;
}
}
final WordComposer composer = new WordComposer();
final int[] codePoints = StringUtils.toCodePointArray(testedWord);

View File

@ -16,18 +16,17 @@
package com.android.inputmethod.latin.utils;
import android.content.Context;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.Suggest;
public class DistracterFilterUtils {
private DistracterFilterUtils() {
// This utility class is not publicly instantiable.
}
public static final DistracterFilter createDistracterFilter(final Context context,
public static final DistracterFilter createDistracterFilter(final Suggest suggest,
final KeyboardSwitcher keyboardSwitcher) {
final MainKeyboardView mainKeyboardView = keyboardSwitcher.getMainKeyboardView();
// TODO: Create Keyboard when mainKeyboardView is null.
@ -35,7 +34,7 @@ public class DistracterFilterUtils {
// spellchecker's logic.
final Keyboard keyboard = (mainKeyboardView != null) ?
mainKeyboardView.getKeyboard() : null;
final DistracterFilter distracterFilter = new DistracterFilter(context, keyboard);
final DistracterFilter distracterFilter = new DistracterFilter(suggest, keyboard);
return distracterFilter;
}
}

View File

@ -150,7 +150,7 @@ public final class LanguageModelParam {
// Adding such a word to dictonaries would interfere with entering in-dictionary words. For
// example, adding "mot" to dictionaries might interfere with entering "not".
// This kind of OOV should be filtered out.
if (distracterFilter.isDistracterToWordsInDictionaries(prevWord, targetWord, locale)) {
if (distracterFilter.isDistracterToWordsInDictionaries(prevWord, targetWord)) {
return null;
}
return createAndGetLanguageModelParamOfWord(prevWord, targetWord, timestamp,