am 41ee1f08: Merge "Enable personalization for multilingual users."

* commit '41ee1f089face03ef951a66fafca5a4462297a0c':
  Enable personalization for multilingual users.
main
Keisuke Kuroyanagi 2014-09-10 10:01:28 +00:00 committed by Android Git Automerger
commit 0d7e3fcc2b
5 changed files with 25 additions and 18 deletions

View File

@ -16,8 +16,6 @@
package com.android.inputmethod.latin.personalization;
import java.util.Locale;
import android.content.Context;
import com.android.inputmethod.latin.DictionaryFacilitator;
@ -33,12 +31,7 @@ public class PersonalizationDictionaryUpdater {
mDictionaryFacilitator = dictionaryFacilitator;
}
public Locale getLocale() {
return null;
}
public void onLoadSettings(final boolean usePersonalizedDicts,
final boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes) {
public void onLoadSettings(final boolean usePersonalizedDicts) {
if (!mDictCleared) {
// Clear and never update the personalization dictionary.
PersonalizationHelper.removeAllPersonalizationDictionaries(mContext);

View File

@ -189,6 +189,10 @@ public class DictionaryFacilitator {
mPersonalizationDictionaryFacilitator.updateEnabledSubtypes(enabledSubtypes);
}
public void setIsMonolingualUser(final boolean isMonolingualUser) {
mPersonalizationDictionaryFacilitator.setIsMonolingualUser(isMonolingualUser);
}
public Locale getLocale() {
return mDictionaryGroup.mLocale;
}
@ -600,7 +604,7 @@ public class DictionaryFacilitator {
final SpacingAndPunctuations spacingAndPunctuations,
final AddMultipleDictionaryEntriesCallback callback) {
mPersonalizationDictionaryFacilitator.addEntriesToPersonalizationDictionariesToUpdate(
personalizationDataChunk, spacingAndPunctuations, callback);
getLocale(), personalizationDataChunk, spacingAndPunctuations, callback);
}
public void addPhraseToContextualDictionary(final String[] phrase, final int probability,

View File

@ -614,9 +614,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void refreshPersonalizationDictionarySession(
final SettingsValues currentSettingsValues) {
mPersonalizationDictionaryUpdater.onLoadSettings(
currentSettingsValues.mUsePersonalizedDicts,
mDictionaryFacilitator.setIsMonolingualUser(
mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes());
mPersonalizationDictionaryUpdater.onLoadSettings(
currentSettingsValues.mUsePersonalizedDicts);
mContextualDictionaryUpdater.onLoadSettings(currentSettingsValues.mUsePersonalizedDicts);
final boolean shouldKeepUserHistoryDictionaries;
if (currentSettingsValues.mUsePersonalizedDicts) {
@ -734,10 +735,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
cleanupInternalStateForFinishInput();
}
}
// TODO: Remove this test.
if (!conf.locale.equals(mPersonalizationDictionaryUpdater.getLocale())) {
refreshPersonalizationDictionarySession(settingsValues);
}
super.onConfigurationChanged(conf);
}

View File

@ -44,6 +44,7 @@ public class PersonalizationDictionaryFacilitator {
private final HashMap<String, HashSet<Locale>> mLangToLocalesMap = new HashMap<>();
private final HashMap<Locale, ExpandableBinaryDictionary> mPersonalizationDictsToUpdate =
new HashMap<>();
private boolean mIsMonolingualUser = false;;
PersonalizationDictionaryFacilitator(final Context context,
final DistracterFilter distracterFilter) {
@ -81,6 +82,10 @@ public class PersonalizationDictionaryFacilitator {
}
}
public void setIsMonolingualUser(final boolean isMonolingualUser) {
mIsMonolingualUser = isMonolingualUser;
}
/**
* Flush personalization dictionaries to dictionary files. Close dictionaries after writing
* files except the dictionary that is used for generating suggestions.
@ -141,12 +146,18 @@ public class PersonalizationDictionaryFacilitator {
personalizationDict.addMultipleDictionaryEntriesDynamically(languageModelParams, callback);
}
public void addEntriesToPersonalizationDictionariesToUpdate(
public void addEntriesToPersonalizationDictionariesToUpdate(final Locale defaultLocale,
final PersonalizationDataChunk personalizationDataChunk,
final SpacingAndPunctuations spacingAndPunctuations,
final AddMultipleDictionaryEntriesCallback callback) {
final HashSet<Locale> locales =
mLangToLocalesMap.get(personalizationDataChunk.mDetectedLanguage);
final String language = personalizationDataChunk.mDetectedLanguage;
final HashSet<Locale> locales;
if (mIsMonolingualUser && PersonalizationDataChunk.LANGUAGE_UNKNOWN.equals(language)
&& mLangToLocalesMap.size() == 1) {
locales = mLangToLocalesMap.get(defaultLocale.getLanguage());
} else {
locales = mLangToLocalesMap.get(language);
}
if (locales == null || locales.isEmpty()) {
if (callback != null) {
callback.onFinished();

View File

@ -20,6 +20,8 @@ import java.util.Collections;
import java.util.List;
public class PersonalizationDataChunk {
public static final String LANGUAGE_UNKNOWN = "";
public final boolean mInputByUser;
public final List<String> mTokens;
public final int mTimestampInSeconds;