Enable personalization for multilingual users.
Bug: 16547557 Change-Id: I03eda34edc902fc4732d16d234216344d8d84d88main
parent
89e34169f8
commit
af1a06d7e1
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue