am 41ee1f08: Merge "Enable personalization for multilingual users."
* commit '41ee1f089face03ef951a66fafca5a4462297a0c': Enable personalization for multilingual users.main
commit
0d7e3fcc2b
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.personalization;
|
package com.android.inputmethod.latin.personalization;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.DictionaryFacilitator;
|
import com.android.inputmethod.latin.DictionaryFacilitator;
|
||||||
|
@ -33,12 +31,7 @@ public class PersonalizationDictionaryUpdater {
|
||||||
mDictionaryFacilitator = dictionaryFacilitator;
|
mDictionaryFacilitator = dictionaryFacilitator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getLocale() {
|
public void onLoadSettings(final boolean usePersonalizedDicts) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onLoadSettings(final boolean usePersonalizedDicts,
|
|
||||||
final boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes) {
|
|
||||||
if (!mDictCleared) {
|
if (!mDictCleared) {
|
||||||
// Clear and never update the personalization dictionary.
|
// Clear and never update the personalization dictionary.
|
||||||
PersonalizationHelper.removeAllPersonalizationDictionaries(mContext);
|
PersonalizationHelper.removeAllPersonalizationDictionaries(mContext);
|
||||||
|
|
|
@ -189,6 +189,10 @@ public class DictionaryFacilitator {
|
||||||
mPersonalizationDictionaryFacilitator.updateEnabledSubtypes(enabledSubtypes);
|
mPersonalizationDictionaryFacilitator.updateEnabledSubtypes(enabledSubtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsMonolingualUser(final boolean isMonolingualUser) {
|
||||||
|
mPersonalizationDictionaryFacilitator.setIsMonolingualUser(isMonolingualUser);
|
||||||
|
}
|
||||||
|
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return mDictionaryGroup.mLocale;
|
return mDictionaryGroup.mLocale;
|
||||||
}
|
}
|
||||||
|
@ -600,7 +604,7 @@ public class DictionaryFacilitator {
|
||||||
final SpacingAndPunctuations spacingAndPunctuations,
|
final SpacingAndPunctuations spacingAndPunctuations,
|
||||||
final AddMultipleDictionaryEntriesCallback callback) {
|
final AddMultipleDictionaryEntriesCallback callback) {
|
||||||
mPersonalizationDictionaryFacilitator.addEntriesToPersonalizationDictionariesToUpdate(
|
mPersonalizationDictionaryFacilitator.addEntriesToPersonalizationDictionariesToUpdate(
|
||||||
personalizationDataChunk, spacingAndPunctuations, callback);
|
getLocale(), personalizationDataChunk, spacingAndPunctuations, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPhraseToContextualDictionary(final String[] phrase, final int probability,
|
public void addPhraseToContextualDictionary(final String[] phrase, final int probability,
|
||||||
|
|
|
@ -614,9 +614,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private void refreshPersonalizationDictionarySession(
|
private void refreshPersonalizationDictionarySession(
|
||||||
final SettingsValues currentSettingsValues) {
|
final SettingsValues currentSettingsValues) {
|
||||||
mPersonalizationDictionaryUpdater.onLoadSettings(
|
mDictionaryFacilitator.setIsMonolingualUser(
|
||||||
currentSettingsValues.mUsePersonalizedDicts,
|
|
||||||
mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes());
|
mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes());
|
||||||
|
mPersonalizationDictionaryUpdater.onLoadSettings(
|
||||||
|
currentSettingsValues.mUsePersonalizedDicts);
|
||||||
mContextualDictionaryUpdater.onLoadSettings(currentSettingsValues.mUsePersonalizedDicts);
|
mContextualDictionaryUpdater.onLoadSettings(currentSettingsValues.mUsePersonalizedDicts);
|
||||||
final boolean shouldKeepUserHistoryDictionaries;
|
final boolean shouldKeepUserHistoryDictionaries;
|
||||||
if (currentSettingsValues.mUsePersonalizedDicts) {
|
if (currentSettingsValues.mUsePersonalizedDicts) {
|
||||||
|
@ -734,10 +735,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
cleanupInternalStateForFinishInput();
|
cleanupInternalStateForFinishInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Remove this test.
|
|
||||||
if (!conf.locale.equals(mPersonalizationDictionaryUpdater.getLocale())) {
|
|
||||||
refreshPersonalizationDictionarySession(settingsValues);
|
|
||||||
}
|
|
||||||
super.onConfigurationChanged(conf);
|
super.onConfigurationChanged(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class PersonalizationDictionaryFacilitator {
|
||||||
private final HashMap<String, HashSet<Locale>> mLangToLocalesMap = new HashMap<>();
|
private final HashMap<String, HashSet<Locale>> mLangToLocalesMap = new HashMap<>();
|
||||||
private final HashMap<Locale, ExpandableBinaryDictionary> mPersonalizationDictsToUpdate =
|
private final HashMap<Locale, ExpandableBinaryDictionary> mPersonalizationDictsToUpdate =
|
||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
|
private boolean mIsMonolingualUser = false;;
|
||||||
|
|
||||||
PersonalizationDictionaryFacilitator(final Context context,
|
PersonalizationDictionaryFacilitator(final Context context,
|
||||||
final DistracterFilter distracterFilter) {
|
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
|
* Flush personalization dictionaries to dictionary files. Close dictionaries after writing
|
||||||
* files except the dictionary that is used for generating suggestions.
|
* files except the dictionary that is used for generating suggestions.
|
||||||
|
@ -141,12 +146,18 @@ public class PersonalizationDictionaryFacilitator {
|
||||||
personalizationDict.addMultipleDictionaryEntriesDynamically(languageModelParams, callback);
|
personalizationDict.addMultipleDictionaryEntriesDynamically(languageModelParams, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntriesToPersonalizationDictionariesToUpdate(
|
public void addEntriesToPersonalizationDictionariesToUpdate(final Locale defaultLocale,
|
||||||
final PersonalizationDataChunk personalizationDataChunk,
|
final PersonalizationDataChunk personalizationDataChunk,
|
||||||
final SpacingAndPunctuations spacingAndPunctuations,
|
final SpacingAndPunctuations spacingAndPunctuations,
|
||||||
final AddMultipleDictionaryEntriesCallback callback) {
|
final AddMultipleDictionaryEntriesCallback callback) {
|
||||||
final HashSet<Locale> locales =
|
final String language = personalizationDataChunk.mDetectedLanguage;
|
||||||
mLangToLocalesMap.get(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 (locales == null || locales.isEmpty()) {
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.onFinished();
|
callback.onFinished();
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PersonalizationDataChunk {
|
public class PersonalizationDataChunk {
|
||||||
|
public static final String LANGUAGE_UNKNOWN = "";
|
||||||
|
|
||||||
public final boolean mInputByUser;
|
public final boolean mInputByUser;
|
||||||
public final List<String> mTokens;
|
public final List<String> mTokens;
|
||||||
public final int mTimestampInSeconds;
|
public final int mTimestampInSeconds;
|
||||||
|
|
Loading…
Reference in New Issue