Merge "Add contextual dictionary to the dictionary facilitator."

This commit is contained in:
Keisuke Kuroyanagi 2014-05-12 04:42:32 +00:00 committed by Android (Google) Code Review
commit 47c76f0a45
3 changed files with 65 additions and 1 deletions

View file

@ -57,6 +57,8 @@ public abstract class Dictionary {
public static final String TYPE_USER_HISTORY = "history";
// Personalization dictionary.
public static final String TYPE_PERSONALIZATION = "personalization";
// Contextual dictionary.
public static final String TYPE_CONTEXTUAL = "contextual";
public final String mDictType;
public Dictionary(final String dictType) {

View file

@ -23,6 +23,7 @@ import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.personalization.ContextualDictionary;
import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
import com.android.inputmethod.latin.utils.CollectionUtils;
@ -63,7 +64,8 @@ public class DictionaryFacilitatorForSuggest {
Dictionary.TYPE_USER_HISTORY,
Dictionary.TYPE_PERSONALIZATION,
Dictionary.TYPE_USER,
Dictionary.TYPE_CONTACTS
Dictionary.TYPE_CONTACTS,
Dictionary.TYPE_CONTEXTUAL
};
private static final Map<String, Class<? extends ExpandableBinaryDictionary>>
@ -74,6 +76,7 @@ public class DictionaryFacilitatorForSuggest {
DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_PERSONALIZATION, PersonalizationDictionary.class);
DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_USER, UserBinaryDictionary.class);
DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_CONTACTS, ContactsBinaryDictionary.class);
DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_CONTEXTUAL, ContextualDictionary.class);
}
private static final String DICT_FACTORY_METHOD_NAME = "getDictionary";
@ -201,6 +204,7 @@ public class DictionaryFacilitatorForSuggest {
if (usePersonalizedDicts) {
subDictTypesToUse.add(Dictionary.TYPE_USER_HISTORY);
subDictTypesToUse.add(Dictionary.TYPE_PERSONALIZATION);
subDictTypesToUse.add(Dictionary.TYPE_CONTEXTUAL);
}
final Dictionary newMainDict;

View file

@ -0,0 +1,58 @@
/*
* 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.personalization;
import android.content.Context;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import java.io.File;
import java.util.Locale;
public class ContextualDictionary extends ExpandableBinaryDictionary {
/* package */ static final String NAME = PersonalizationDictionary.class.getSimpleName();
private ContextualDictionary(final Context context, final Locale locale,
final File dictFile) {
super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_CONTEXTUAL,
dictFile);
// Always reset the contents.
clear();
}
@UsedForTesting
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
final File dictFile) {
return new ContextualDictionary(context, locale, dictFile);
}
@Override
public boolean isValidWord(final String word) {
// Strings out of this dictionary should not be considered existing words.
return false;
}
@Override
protected void loadInitialContentsLocked() {
}
@Override
protected boolean haveContentsChanged() {
return false;
}
}