am 6b64de50: Merge "Add languageWeight as an argument of getSuggestions."
* commit '6b64de50630663d20961b28788090dc049856d3a': Add languageWeight as an argument of getSuggestions.main
commit
74343a5031
|
@ -231,16 +231,17 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions, 0 /* sessionId */);
|
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
if (!isValidDictionary()) return null;
|
if (!isValidDictionary()) return null;
|
||||||
|
|
||||||
Arrays.fill(mInputCodePoints, Constants.NOT_A_CODE);
|
Arrays.fill(mInputCodePoints, Constants.NOT_A_CODE);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public abstract class Dictionary {
|
public abstract class Dictionary {
|
||||||
public static final int NOT_A_PROBABILITY = -1;
|
public static final int NOT_A_PROBABILITY = -1;
|
||||||
|
public static final float NOT_A_LANGUAGE_WEIGHT = -1.0f;
|
||||||
|
|
||||||
// The following types do not actually come from real dictionary instances, so we create
|
// The following types do not actually come from real dictionary instances, so we create
|
||||||
// corresponding instances.
|
// corresponding instances.
|
||||||
|
@ -70,22 +71,26 @@ public abstract class Dictionary {
|
||||||
* @param proximityInfo the object for key proximity. May be ignored by some implementations.
|
* @param proximityInfo the object for key proximity. May be ignored by some implementations.
|
||||||
* @param blockOffensiveWords whether to block potentially offensive words
|
* @param blockOffensiveWords whether to block potentially offensive words
|
||||||
* @param additionalFeaturesOptions options about additional features used for the suggestion.
|
* @param additionalFeaturesOptions options about additional features used for the suggestion.
|
||||||
|
* @param inOutLanguageWeight the language weight used for generating suggestions.
|
||||||
|
* inOutLanguageWeight is a float array that has only one element. This can be updated when the
|
||||||
|
* different language weight is used.
|
||||||
* @return the list of suggestions (possibly null if none)
|
* @return the list of suggestions (possibly null if none)
|
||||||
*/
|
*/
|
||||||
// TODO: pass more context than just the previous word, to enable better suggestions (n-gram
|
// TODO: pass more context than just the previous word, to enable better suggestions (n-gram
|
||||||
// and more)
|
// and more)
|
||||||
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions);
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight);
|
||||||
|
|
||||||
// The default implementation of this method ignores sessionId.
|
// The default implementation of this method ignores sessionId.
|
||||||
// Subclasses that want to use sessionId need to override this method.
|
// Subclasses that want to use sessionId need to override this method.
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
return getSuggestions(composer, prevWord, proximityInfo, blockOffensiveWords,
|
return getSuggestions(composer, prevWord, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions);
|
additionalFeaturesOptions, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +164,8 @@ public abstract class Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,18 +58,21 @@ public final class DictionaryCollection extends Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
|
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
|
||||||
if (dictionaries.isEmpty()) return null;
|
if (dictionaries.isEmpty()) return null;
|
||||||
// To avoid creating unnecessary objects, we get the list out of the first
|
// To avoid creating unnecessary objects, we get the list out of the first
|
||||||
// dictionary and add the rest to it if not null, hence the get(0)
|
// dictionary and add the rest to it if not null, hence the get(0)
|
||||||
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer,
|
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer,
|
||||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions);
|
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||||
|
inOutLanguageWeight);
|
||||||
if (null == suggestions) suggestions = CollectionUtils.newArrayList();
|
if (null == suggestions) suggestions = CollectionUtils.newArrayList();
|
||||||
final int length = dictionaries.size();
|
final int length = dictionaries.size();
|
||||||
for (int i = 1; i < length; ++ i) {
|
for (int i = 1; i < length; ++ i) {
|
||||||
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer,
|
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer,
|
||||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions);
|
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||||
|
inOutLanguageWeight);
|
||||||
if (null != sugg) suggestions.addAll(sugg);
|
if (null != sugg) suggestions.addAll(sugg);
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
|
|
|
@ -461,12 +461,14 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
final Map<String, Dictionary> dictMap = dictionaries.mDictMap;
|
final Map<String, Dictionary> dictMap = dictionaries.mDictMap;
|
||||||
final SuggestionResults suggestionResults =
|
final SuggestionResults suggestionResults =
|
||||||
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS);
|
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS);
|
||||||
|
final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT };
|
||||||
for (final String dictType : dictTypesOrderedToGetSuggestion) {
|
for (final String dictType : dictTypesOrderedToGetSuggestion) {
|
||||||
final Dictionary dictionary = dictMap.get(dictType);
|
final Dictionary dictionary = dictMap.get(dictType);
|
||||||
if (null == dictionary) continue;
|
if (null == dictionary) continue;
|
||||||
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
||||||
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
|
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions, sessionId);
|
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||||
|
languageWeight);
|
||||||
if (null == dictionarySuggestions) continue;
|
if (null == dictionarySuggestions) continue;
|
||||||
suggestionResults.addAll(dictionarySuggestions);
|
suggestionResults.addAll(dictionarySuggestions);
|
||||||
if (null != rawSuggestions) {
|
if (null != rawSuggestions) {
|
||||||
|
|
|
@ -387,7 +387,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
reloadDictionaryIfRequired();
|
reloadDictionaryIfRequired();
|
||||||
if (processingLargeTask()) {
|
if (processingLargeTask()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -404,7 +404,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
final ArrayList<SuggestedWordInfo> binarySuggestion =
|
final ArrayList<SuggestedWordInfo> binarySuggestion =
|
||||||
mBinaryDictionary.getSuggestionsWithSessionId(composer, prevWord,
|
mBinaryDictionary.getSuggestionsWithSessionId(composer, prevWord,
|
||||||
proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||||
sessionId);
|
sessionId, inOutLanguageWeight);
|
||||||
holder.set(binarySuggestion);
|
holder.set(binarySuggestion);
|
||||||
if (mBinaryDictionary.isCorrupted()) {
|
if (mBinaryDictionary.isCorrupted()) {
|
||||||
removeBinaryDictionaryLocked();
|
removeBinaryDictionaryLocked();
|
||||||
|
@ -417,9 +417,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions, 0 /* sessionId */);
|
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,20 +51,21 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions, 0 /* sessionId */);
|
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
if (mLock.readLock().tryLock()) {
|
if (mLock.readLock().tryLock()) {
|
||||||
try {
|
try {
|
||||||
return mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
|
return mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions);
|
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
||||||
} finally {
|
} finally {
|
||||||
mLock.readLock().unlock();
|
mLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,11 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions);
|
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,11 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions);
|
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,8 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
final ArrayList<SuggestedWordInfo> suggestions =
|
final ArrayList<SuggestedWordInfo> suggestions =
|
||||||
dictInfo.mDictionary.getSuggestions(composer, prevWord,
|
dictInfo.mDictionary.getSuggestions(composer, prevWord,
|
||||||
dictInfo.getProximityInfo(), true /* blockOffensiveWords */,
|
dictInfo.getProximityInfo(), true /* blockOffensiveWords */,
|
||||||
null /* additionalFeaturesOptions */);
|
null /* additionalFeaturesOptions */,
|
||||||
|
null /* inOutLanguageWeight */);
|
||||||
if (suggestions != null) {
|
if (suggestions != null) {
|
||||||
for (final SuggestedWordInfo suggestion : suggestions) {
|
for (final SuggestedWordInfo suggestion : suggestions) {
|
||||||
final String suggestionStr = suggestion.mWord;
|
final String suggestionStr = suggestion.mWord;
|
||||||
|
|
|
@ -53,7 +53,8 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
final String prevWord, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
|
final float[] inOutLanguageWeight) {
|
||||||
return noSuggestions;
|
return noSuggestions;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue