am c0eb5712: Don\'t check user dictionary, except for spelling.
* commit 'c0eb57124fd295ceb85c3350de3189c40594ee96': Don't check user dictionary, except for spelling.main
commit
68946c796d
|
@ -135,7 +135,9 @@ public interface DictionaryFacilitator {
|
||||||
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId,
|
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId,
|
||||||
final int inputStyle, final KeyboardLayout keyboardLayout);
|
final int inputStyle, final KeyboardLayout keyboardLayout);
|
||||||
|
|
||||||
boolean isValidWord(final String word, final boolean ignoreCase);
|
boolean isValidSpellingWord(final String word);
|
||||||
|
|
||||||
|
boolean isValidSuggestionWord(final String word);
|
||||||
|
|
||||||
int getFrequency(final String word);
|
int getFrequency(final String word);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -79,13 +78,33 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final DistracterFilter mDistracterFilter;
|
private final DistracterFilter mDistracterFilter;
|
||||||
|
|
||||||
private static final String[] DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS =
|
private static final String[] ALL_DICTIONARY_TYPES = new String[] {
|
||||||
new String[] {
|
|
||||||
Dictionary.TYPE_MAIN,
|
Dictionary.TYPE_MAIN,
|
||||||
Dictionary.TYPE_USER_HISTORY,
|
Dictionary.TYPE_USER_HISTORY,
|
||||||
Dictionary.TYPE_USER,
|
Dictionary.TYPE_USER,
|
||||||
Dictionary.TYPE_CONTACTS,
|
Dictionary.TYPE_CONTACTS};
|
||||||
};
|
|
||||||
|
private static final String[] SUB_DICTIONARY_TYPES = new String[] {
|
||||||
|
Dictionary.TYPE_USER_HISTORY,
|
||||||
|
Dictionary.TYPE_USER,
|
||||||
|
Dictionary.TYPE_CONTACTS};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
|
||||||
|
*/
|
||||||
|
private static final String[] DICTIONARY_TYPES_FOR_SPELLING = new String[] {
|
||||||
|
Dictionary.TYPE_MAIN,
|
||||||
|
Dictionary.TYPE_USER_HISTORY,
|
||||||
|
Dictionary.TYPE_USER,
|
||||||
|
Dictionary.TYPE_CONTACTS};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
|
||||||
|
*/
|
||||||
|
private static final String[] DICTIONARY_TYPES_FOR_SUGGESTIONS = new String[] {
|
||||||
|
Dictionary.TYPE_MAIN,
|
||||||
|
Dictionary.TYPE_USER_HISTORY,
|
||||||
|
Dictionary.TYPE_CONTACTS};
|
||||||
|
|
||||||
public static final Map<String, Class<? extends ExpandableBinaryDictionary>>
|
public static final Map<String, Class<? extends ExpandableBinaryDictionary>>
|
||||||
DICT_TYPE_TO_CLASS = new HashMap<>();
|
DICT_TYPE_TO_CLASS = new HashMap<>();
|
||||||
|
@ -100,10 +119,6 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
private static final Class<?>[] DICT_FACTORY_METHOD_ARG_TYPES =
|
private static final Class<?>[] DICT_FACTORY_METHOD_ARG_TYPES =
|
||||||
new Class[] { Context.class, Locale.class, File.class, String.class, String.class };
|
new Class[] { Context.class, Locale.class, File.class, String.class, String.class };
|
||||||
|
|
||||||
private static final String[] SUB_DICT_TYPES =
|
|
||||||
Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */,
|
|
||||||
DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS.length);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this facilitator is exactly for this list of locales.
|
* Returns whether this facilitator is exactly for this list of locales.
|
||||||
*
|
*
|
||||||
|
@ -404,7 +419,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
if (null == currentDictionaryGroupForLocale) {
|
if (null == currentDictionaryGroupForLocale) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final String dictType : SUB_DICT_TYPES) {
|
for (final String dictType : SUB_DICTIONARY_TYPES) {
|
||||||
if (currentDictionaryGroupForLocale.hasDict(dictType, account)) {
|
if (currentDictionaryGroupForLocale.hasDict(dictType, account)) {
|
||||||
dictTypeForLocale.add(dictType);
|
dictTypeForLocale.add(dictType);
|
||||||
}
|
}
|
||||||
|
@ -563,7 +578,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
mDictionaryGroups = new DictionaryGroup[] { mMostProbableDictionaryGroup };
|
mDictionaryGroups = new DictionaryGroup[] { mMostProbableDictionaryGroup };
|
||||||
}
|
}
|
||||||
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
||||||
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
for (final String dictType : ALL_DICTIONARY_TYPES) {
|
||||||
dictionaryGroup.closeDict(dictType);
|
dictionaryGroup.closeDict(dictType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,8 +663,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
final String lowerCasedWord = word.toLowerCase(dictionaryGroup.mLocale);
|
final String lowerCasedWord = word.toLowerCase(dictionaryGroup.mLocale);
|
||||||
final String secondWord;
|
final String secondWord;
|
||||||
if (wasAutoCapitalized) {
|
if (wasAutoCapitalized) {
|
||||||
if (isValidWord(word, false /* ignoreCase */)
|
if (isValidSuggestionWord(word) && !isValidSuggestionWord(lowerCasedWord)) {
|
||||||
&& !isValidWord(lowerCasedWord, false /* ignoreCase */)) {
|
|
||||||
// If the word was auto-capitalized and exists only as a capitalized word in the
|
// If the word was auto-capitalized and exists only as a capitalized word in the
|
||||||
// dictionary, then we must not downcase it before registering it. For example,
|
// dictionary, then we must not downcase it before registering it. For example,
|
||||||
// the name of the contacts in start-of-sentence position would come here with the
|
// the name of the contacts in start-of-sentence position would come here with the
|
||||||
|
@ -711,7 +725,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
final float[] weightOfLangModelVsSpatialModel =
|
final float[] weightOfLangModelVsSpatialModel =
|
||||||
new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL };
|
new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL };
|
||||||
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
||||||
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
for (final String dictType : DICTIONARY_TYPES_FOR_SUGGESTIONS) {
|
||||||
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
||||||
if (null == dictionary) continue;
|
if (null == dictionary) continue;
|
||||||
final float weightForLocale = composer.isBatchMode()
|
final float weightForLocale = composer.isBatchMode()
|
||||||
|
@ -731,7 +745,15 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
return suggestionResults;
|
return suggestionResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidWord(final String word, final boolean ignoreCase) {
|
public boolean isValidSpellingWord(final String word) {
|
||||||
|
return isValidWord(word, DICTIONARY_TYPES_FOR_SPELLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidSuggestionWord(final String word) {
|
||||||
|
return isValidWord(word, DICTIONARY_TYPES_FOR_SUGGESTIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidWord(final String word, final String[] dictionariesToCheck) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -740,15 +762,13 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
if (dictionaryGroup.mLocale == null) {
|
if (dictionaryGroup.mLocale == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String lowerCasedWord = word.toLowerCase(dictionaryGroup.mLocale);
|
for (final String dictType : dictionariesToCheck) {
|
||||||
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
|
||||||
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
||||||
// Ideally the passed map would come out of a {@link java.util.concurrent.Future} and
|
// Ideally the passed map would come out of a {@link java.util.concurrent.Future} and
|
||||||
// would be immutable once it's finished initializing, but concretely a null test is
|
// would be immutable once it's finished initializing, but concretely a null test is
|
||||||
// probably good enough for the time being.
|
// probably good enough for the time being.
|
||||||
if (null == dictionary) continue;
|
if (null == dictionary) continue;
|
||||||
if (dictionary.isValidWord(word)
|
if (dictionary.isValidWord(word)) {
|
||||||
|| (ignoreCase && dictionary.isValidWord(lowerCasedWord))) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -764,7 +784,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
int maxFreq = Dictionary.NOT_A_PROBABILITY;
|
int maxFreq = Dictionary.NOT_A_PROBABILITY;
|
||||||
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
||||||
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
||||||
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
|
for (final String dictType : ALL_DICTIONARY_TYPES) {
|
||||||
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
final Dictionary dictionary = dictionaryGroup.getDict(dictType);
|
||||||
if (dictionary == null) continue;
|
if (dictionary == null) continue;
|
||||||
final int tempFreq;
|
final int tempFreq;
|
||||||
|
@ -820,7 +840,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
final ArrayList<Pair<String, DictionaryStats>> statsOfEnabledSubDicts = new ArrayList<>();
|
final ArrayList<Pair<String, DictionaryStats>> statsOfEnabledSubDicts = new ArrayList<>();
|
||||||
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
final DictionaryGroup[] dictionaryGroups = mDictionaryGroups;
|
||||||
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
for (final DictionaryGroup dictionaryGroup : dictionaryGroups) {
|
||||||
for (final String dictType : SUB_DICT_TYPES) {
|
for (final String dictType : SUB_DICTIONARY_TYPES) {
|
||||||
final ExpandableBinaryDictionary dictionary = dictionaryGroup.getSubDict(dictType);
|
final ExpandableBinaryDictionary dictionary = dictionaryGroup.getSubDict(dictType);
|
||||||
if (dictionary == null) continue;
|
if (dictionary == null) continue;
|
||||||
statsOfEnabledSubDicts.add(new Pair<>(dictType, dictionary.getDictionaryStats()));
|
statsOfEnabledSubDicts.add(new Pair<>(dictType, dictionary.getDictionaryStats()));
|
||||||
|
|
|
@ -154,7 +154,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
try {
|
try {
|
||||||
DictionaryFacilitator dictionaryFacilitatorForLocale =
|
DictionaryFacilitator dictionaryFacilitatorForLocale =
|
||||||
mDictionaryFacilitatorCache.get(locale);
|
mDictionaryFacilitatorCache.get(locale);
|
||||||
return dictionaryFacilitatorForLocale.isValidWord(word, false /* igroreCase */);
|
return dictionaryFacilitatorForLocale.isValidSpellingWord(word);
|
||||||
} finally {
|
} finally {
|
||||||
mSemaphore.release();
|
mSemaphore.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,8 +196,7 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
|
||||||
mDistractersCache.put(cacheKey, Boolean.TRUE);
|
mDistractersCache.put(cacheKey, Boolean.TRUE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final boolean Word = dictionaryFacilitator.isValidWord(testedWord, false /* ignoreCase */);
|
if (dictionaryFacilitator.isValidSuggestionWord(testedWord)) {
|
||||||
if (Word) {
|
|
||||||
// Valid word is not a distracter.
|
// Valid word is not a distracter.
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "isDistracter: false (valid word)");
|
Log.d(TAG, "isDistracter: false (valid word)");
|
||||||
|
@ -291,14 +290,14 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
final DictionaryFacilitator dictionaryFacilitator =
|
final DictionaryFacilitator dictionaryFacilitator =
|
||||||
mDictionaryFacilitatorLruCache.get(locale);
|
mDictionaryFacilitatorLruCache.get(locale);
|
||||||
if (dictionaryFacilitator.isValidWord(testedWord, false /* ignoreCase */)) {
|
if (dictionaryFacilitator.isValidSuggestionWord(testedWord)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String lowerCaseTargetWord = testedWord.toLowerCase(locale);
|
final String lowerCaseWord = testedWord.toLowerCase(locale);
|
||||||
if (testedWord.equals(lowerCaseTargetWord)) {
|
if (testedWord.equals(lowerCaseWord)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (dictionaryFacilitator.isValidWord(lowerCaseTargetWord, false /* ignoreCase */)) {
|
if (dictionaryFacilitator.isValidSuggestionWord(lowerCaseWord)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (StringUtils.getCapitalizationType(testedWord) == StringUtils.CAPITALIZE_FIRST
|
if (StringUtils.getCapitalizationType(testedWord) == StringUtils.CAPITALIZE_FIRST
|
||||||
|
@ -317,10 +316,10 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
|
||||||
return HandlingType.getHandlingType(false /* shouldBeLowerCased */, false /* isOov */);
|
return HandlingType.getHandlingType(false /* shouldBeLowerCased */, false /* isOov */);
|
||||||
}
|
}
|
||||||
final boolean shouldBeLowerCased = shouldBeLowerCased(ngramContext, testedWord, locale);
|
final boolean shouldBeLowerCased = shouldBeLowerCased(ngramContext, testedWord, locale);
|
||||||
final String caseModifiedWord =
|
final String caseModifiedWord = shouldBeLowerCased
|
||||||
shouldBeLowerCased ? testedWord.toLowerCase(locale) : testedWord;
|
? testedWord.toLowerCase(locale) : testedWord;
|
||||||
final boolean isOov = !mDictionaryFacilitatorLruCache.get(locale).isValidWord(
|
final boolean isOov = !mDictionaryFacilitatorLruCache.get(locale).isValidSuggestionWord(
|
||||||
caseModifiedWord, false /* ignoreCase */);
|
caseModifiedWord);
|
||||||
return HandlingType.getHandlingType(shouldBeLowerCased, isOov);
|
return HandlingType.getHandlingType(shouldBeLowerCased, isOov);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue