Make session id mandatory for getSuggestions.
Bug: 15008504 Change-Id: Ic4a17a4b7242118ae74fd89c695da2bb52204fb2
This commit is contained in:
parent
cfd3093362
commit
09c72207c6
10 changed files with 21 additions and 60 deletions
|
@ -113,11 +113,8 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
synchronized(mDicTraverseSessions) {
|
synchronized(mDicTraverseSessions) {
|
||||||
DicTraverseSession traverseSession = mDicTraverseSessions.get(traverseSessionId);
|
DicTraverseSession traverseSession = mDicTraverseSessions.get(traverseSessionId);
|
||||||
if (traverseSession == null) {
|
if (traverseSession == null) {
|
||||||
traverseSession = mDicTraverseSessions.get(traverseSessionId);
|
traverseSession = new DicTraverseSession(mLocale, mNativeDict, mDictSize);
|
||||||
if (traverseSession == null) {
|
mDicTraverseSessions.put(traverseSessionId, traverseSession);
|
||||||
traverseSession = new DicTraverseSession(mLocale, mNativeDict, mDictSize);
|
|
||||||
mDicTraverseSessions.put(traverseSessionId, traverseSession);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return traverseSession;
|
return traverseSession;
|
||||||
}
|
}
|
||||||
|
@ -266,18 +263,8 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
new FormatSpec.FormatOptions(outFormatVersion[0], hasHistoricalInfo));
|
new FormatSpec.FormatOptions(outFormatVersion[0], hasHistoricalInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
|
||||||
final float[] inOutLanguageWeight) {
|
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
|
||||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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 float[] inOutLanguageWeight) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
|
|
|
@ -73,6 +73,7 @@ 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 sessionId the session id.
|
||||||
* @param inOutLanguageWeight the language weight used for generating suggestions.
|
* @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
|
* inOutLanguageWeight is a float array that has only one element. This can be updated when the
|
||||||
* different language weight is used.
|
* different language weight is used.
|
||||||
|
@ -83,17 +84,7 @@ public abstract class Dictionary {
|
||||||
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);
|
final int sessionId, 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 float[] inOutLanguageWeight) {
|
|
||||||
return getSuggestions(composer, prevWord, proximityInfo, blockOffensiveWords,
|
|
||||||
additionalFeaturesOptions, inOutLanguageWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given word occurs in the dictionary
|
* Checks if the given word occurs in the dictionary
|
||||||
|
@ -167,7 +158,7 @@ public abstract class Dictionary {
|
||||||
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 int sessionId, final float[] inOutLanguageWeight) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,20 +59,20 @@ public final class DictionaryCollection extends Dictionary {
|
||||||
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 int sessionId, 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);
|
sessionId, 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);
|
sessionId, inOutLanguageWeight);
|
||||||
if (null != sugg) suggestions.addAll(sugg);
|
if (null != sugg) suggestions.addAll(sugg);
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
|
|
|
@ -455,7 +455,7 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
final Dictionary dictionary = dictionaries.getDict(dictType);
|
final Dictionary dictionary = dictionaries.getDict(dictType);
|
||||||
if (null == dictionary) continue;
|
if (null == dictionary) continue;
|
||||||
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
|
||||||
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
|
dictionary.getSuggestions(composer, prevWord, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||||
languageWeight);
|
languageWeight);
|
||||||
if (null == dictionarySuggestions) continue;
|
if (null == dictionarySuggestions) continue;
|
||||||
|
|
|
@ -366,7 +366,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(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 int sessionId, final float[] inOutLanguageWeight) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
|
@ -380,9 +380,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final ArrayList<SuggestedWordInfo> suggestions =
|
final ArrayList<SuggestedWordInfo> suggestions =
|
||||||
mBinaryDictionary.getSuggestionsWithSessionId(composer, prevWord,
|
mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
|
||||||
proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
|
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||||
sessionId, inOutLanguageWeight);
|
inOutLanguageWeight);
|
||||||
if (mBinaryDictionary.isCorrupted()) {
|
if (mBinaryDictionary.isCorrupted()) {
|
||||||
Log.i(TAG, "Dictionary (" + mDictName +") is corrupted. "
|
Log.i(TAG, "Dictionary (" + mDictName +") is corrupted. "
|
||||||
+ "Remove and regenerate it.");
|
+ "Remove and regenerate it.");
|
||||||
|
@ -400,15 +400,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
|
||||||
final String prevWord, final ProximityInfo proximityInfo,
|
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
|
||||||
final float[] inOutLanguageWeight) {
|
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
|
||||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isValidWord(final String word) {
|
||||||
reloadDictionaryIfRequired();
|
reloadDictionaryIfRequired();
|
||||||
|
|
|
@ -50,22 +50,14 @@ 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 boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
|
||||||
final float[] inOutLanguageWeight) {
|
|
||||||
return getSuggestionsWithSessionId(composer, prevWord, proximityInfo, blockOffensiveWords,
|
|
||||||
additionalFeaturesOptions, 0 /* sessionId */, inOutLanguageWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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 float[] inOutLanguageWeight) {
|
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, inOutLanguageWeight);
|
blockOffensiveWords, additionalFeaturesOptions, sessionId,
|
||||||
|
inOutLanguageWeight);
|
||||||
} finally {
|
} finally {
|
||||||
mLock.readLock().unlock();
|
mLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,7 +327,7 @@ 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 */, 0 /* sessionId */,
|
||||||
null /* inOutLanguageWeight */);
|
null /* inOutLanguageWeight */);
|
||||||
if (suggestions != null) {
|
if (suggestions != null) {
|
||||||
for (final SuggestedWordInfo suggestion : suggestions) {
|
for (final SuggestedWordInfo suggestion : suggestions) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> {
|
||||||
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 int sessionId, final float[] inOutLanguageWeight) {
|
||||||
return noSuggestions;
|
return noSuggestions;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,10 +38,10 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
|
||||||
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) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
blockOffensiveWords, additionalFeaturesOptions, sessionId, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,10 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
|
||||||
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) {
|
final int sessionId, final float[] inOutLanguageWeight) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
|
||||||
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
|
blockOffensiveWords, additionalFeaturesOptions, sessionId, inOutLanguageWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue