Merge "Add languageWeight as an argument of getSuggestions."
This commit is contained in:
commit
6b64de5063
10 changed files with 43 additions and 25 deletions
|
@ -231,16 +231,17 @@ public final class BinaryDictionary extends Dictionary {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
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,
|
||||
additionalFeaturesOptions, 0 /* sessionId */);
|
||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final int sessionId) {
|
||||
final int sessionId, final float[] inOutLanguageWeight) {
|
||||
if (!isValidDictionary()) return null;
|
||||
|
||||
Arrays.fill(mInputCodePoints, Constants.NOT_A_CODE);
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public abstract class Dictionary {
|
||||
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
|
||||
// corresponding instances.
|
||||
|
@ -70,22 +71,26 @@ public abstract class Dictionary {
|
|||
* @param proximityInfo the object for key proximity. May be ignored by some implementations.
|
||||
* @param blockOffensiveWords whether to block potentially offensive words
|
||||
* @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)
|
||||
*/
|
||||
// TODO: pass more context than just the previous word, to enable better suggestions (n-gram
|
||||
// and more)
|
||||
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
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.
|
||||
// Subclasses that want to use sessionId need to override this method.
|
||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final int sessionId) {
|
||||
final int sessionId, final float[] inOutLanguageWeight) {
|
||||
return getSuggestions(composer, prevWord, proximityInfo, blockOffensiveWords,
|
||||
additionalFeaturesOptions);
|
||||
additionalFeaturesOptions, inOutLanguageWeight);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +164,8 @@ public abstract class Dictionary {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final float[] inOutLanguageWeight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,18 +58,21 @@ public final class DictionaryCollection extends Dictionary {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
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;
|
||||
if (dictionaries.isEmpty()) return null;
|
||||
// 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)
|
||||
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer,
|
||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions);
|
||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||
inOutLanguageWeight);
|
||||
if (null == suggestions) suggestions = CollectionUtils.newArrayList();
|
||||
final int length = dictionaries.size();
|
||||
for (int i = 1; i < length; ++ i) {
|
||||
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer,
|
||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions);
|
||||
prevWord, proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||
inOutLanguageWeight);
|
||||
if (null != sugg) suggestions.addAll(sugg);
|
||||
}
|
||||
return suggestions;
|
||||
|
|
|
@ -461,12 +461,14 @@ public class DictionaryFacilitatorForSuggest {
|
|||
final Map<String, Dictionary> dictMap = dictionaries.mDictMap;
|
||||
final SuggestionResults suggestionResults =
|
||||
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS);
|
||||
final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT };
|
||||
for (final String dictType : dictTypesOrderedToGetSuggestion) {
|
||||
final Dictionary dictionary = dictMap.get(dictType);
|
||||
if (null == dictionary) continue;
|
||||
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
||||
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
|
||||
blockOffensiveWords, additionalFeaturesOptions, sessionId);
|
||||
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||
languageWeight);
|
||||
if (null == dictionarySuggestions) continue;
|
||||
suggestionResults.addAll(dictionarySuggestions);
|
||||
if (null != rawSuggestions) {
|
||||
|
|
|
@ -387,7 +387,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final int sessionId) {
|
||||
final int sessionId, final float[] inOutLanguageWeight) {
|
||||
reloadDictionaryIfRequired();
|
||||
if (processingLargeTask()) {
|
||||
return null;
|
||||
|
@ -404,7 +404,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
final ArrayList<SuggestedWordInfo> binarySuggestion =
|
||||
mBinaryDictionary.getSuggestionsWithSessionId(composer, prevWord,
|
||||
proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
||||
sessionId);
|
||||
sessionId, inOutLanguageWeight);
|
||||
holder.set(binarySuggestion);
|
||||
if (mBinaryDictionary.isCorrupted()) {
|
||||
removeBinaryDictionaryLocked();
|
||||
|
@ -417,9 +417,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
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,
|
||||
additionalFeaturesOptions, 0 /* sessionId */);
|
||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,20 +51,21 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
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,
|
||||
additionalFeaturesOptions, 0 /* sessionId */);
|
||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final int sessionId) {
|
||||
final int sessionId, final float[] inOutLanguageWeight) {
|
||||
if (mLock.readLock().tryLock()) {
|
||||
try {
|
||||
return mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
|
||||
blockOffensiveWords, additionalFeaturesOptions);
|
||||
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
||||
} finally {
|
||||
mLock.readLock().unlock();
|
||||
}
|
||||
|
|
|
@ -34,10 +34,11 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final float[] inOutLanguageWeight) {
|
||||
synchronized (mLock) {
|
||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
||||
blockOffensiveWords, additionalFeaturesOptions);
|
||||
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,11 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||
final String prevWordForBigrams, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final float[] inOutLanguageWeight) {
|
||||
synchronized (mLock) {
|
||||
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 =
|
||||
dictInfo.mDictionary.getSuggestions(composer, prevWord,
|
||||
dictInfo.getProximityInfo(), true /* blockOffensiveWords */,
|
||||
null /* additionalFeaturesOptions */);
|
||||
null /* additionalFeaturesOptions */,
|
||||
null /* inOutLanguageWeight */);
|
||||
if (suggestions != null) {
|
||||
for (final SuggestedWordInfo suggestion : suggestions) {
|
||||
final String suggestionStr = suggestion.mWord;
|
||||
|
|
|
@ -53,7 +53,8 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> {
|
|||
@Override
|
||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||
final String prevWord, final ProximityInfo proximityInfo,
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) {
|
||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||
final float[] inOutLanguageWeight) {
|
||||
return noSuggestions;
|
||||
}
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue