am d1f9ce00: Merge "Make session id mandatory for getSuggestions."

* commit 'd1f9ce00db1013e38ce07979aae364287435fa37':
  Make session id mandatory for getSuggestions.
main
Keisuke Kuroyanagi 2014-05-16 09:35:22 +00:00 committed by Android Git Automerger
commit f8b4d5846e
10 changed files with 21 additions and 60 deletions

View File

@ -113,11 +113,8 @@ public final class BinaryDictionary extends Dictionary {
synchronized(mDicTraverseSessions) {
DicTraverseSession traverseSession = mDicTraverseSessions.get(traverseSessionId);
if (traverseSession == null) {
traverseSession = mDicTraverseSessions.get(traverseSessionId);
if (traverseSession == null) {
traverseSession = new DicTraverseSession(mLocale, mNativeDict, mDictSize);
mDicTraverseSessions.put(traverseSessionId, traverseSession);
}
traverseSession = new DicTraverseSession(mLocale, mNativeDict, mDictSize);
mDicTraverseSessions.put(traverseSessionId, traverseSession);
}
return traverseSession;
}
@ -266,18 +263,8 @@ public final class BinaryDictionary extends Dictionary {
new FormatSpec.FormatOptions(outFormatVersion[0], hasHistoricalInfo));
}
@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
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) {

View File

@ -73,6 +73,7 @@ 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 sessionId the session id.
* @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.
@ -83,17 +84,7 @@ public abstract class Dictionary {
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo,
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 float[] inOutLanguageWeight) {
return getSuggestions(composer, prevWord, proximityInfo, blockOffensiveWords,
additionalFeaturesOptions, inOutLanguageWeight);
}
final int sessionId, final float[] inOutLanguageWeight);
/**
* Checks if the given word occurs in the dictionary
@ -167,7 +158,7 @@ public abstract class Dictionary {
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final float[] inOutLanguageWeight) {
final int sessionId, final float[] inOutLanguageWeight) {
return null;
}

View File

@ -59,20 +59,20 @@ public final class DictionaryCollection extends Dictionary {
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final float[] inOutLanguageWeight) {
final int sessionId, 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,
inOutLanguageWeight);
sessionId, 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,
inOutLanguageWeight);
sessionId, inOutLanguageWeight);
if (null != sugg) suggestions.addAll(sugg);
}
return suggestions;

View File

@ -455,7 +455,7 @@ public class DictionaryFacilitatorForSuggest {
final Dictionary dictionary = dictionaries.getDict(dictType);
if (null == dictionary) continue;
final ArrayList<SuggestedWordInfo> dictionarySuggestions =
dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
dictionary.getSuggestions(composer, prevWord, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, sessionId,
languageWeight);
if (null == dictionarySuggestions) continue;

View File

@ -366,7 +366,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
@Override
public ArrayList<SuggestedWordInfo> getSuggestionsWithSessionId(final WordComposer composer,
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final int sessionId, final float[] inOutLanguageWeight) {
@ -380,9 +380,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
return null;
}
final ArrayList<SuggestedWordInfo> suggestions =
mBinaryDictionary.getSuggestionsWithSessionId(composer, prevWord,
proximityInfo, blockOffensiveWords, additionalFeaturesOptions,
sessionId, inOutLanguageWeight);
mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, sessionId,
inOutLanguageWeight);
if (mBinaryDictionary.isCorrupted()) {
Log.i(TAG, "Dictionary (" + mDictName +") is corrupted. "
+ "Remove and regenerate it.");
@ -400,15 +400,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
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
public boolean isValidWord(final String word) {
reloadDictionaryIfRequired();

View File

@ -50,22 +50,14 @@ 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 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 boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final int sessionId, final float[] inOutLanguageWeight) {
if (mLock.readLock().tryLock()) {
try {
return mBinaryDictionary.getSuggestions(composer, prevWord, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
blockOffensiveWords, additionalFeaturesOptions, sessionId,
inOutLanguageWeight);
} finally {
mLock.readLock().unlock();
}

View File

@ -327,7 +327,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
final ArrayList<SuggestedWordInfo> suggestions =
dictInfo.mDictionary.getSuggestions(composer, prevWord,
dictInfo.getProximityInfo(), true /* blockOffensiveWords */,
null /* additionalFeaturesOptions */,
null /* additionalFeaturesOptions */, 0 /* sessionId */,
null /* inOutLanguageWeight */);
if (suggestions != null) {
for (final SuggestedWordInfo suggestion : suggestions) {

View File

@ -54,7 +54,7 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> {
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
final String prevWord, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final float[] inOutLanguageWeight) {
final int sessionId, final float[] inOutLanguageWeight) {
return noSuggestions;
}
@Override

View File

@ -38,10 +38,10 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
final String prevWordForBigrams, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final float[] inOutLanguageWeight) {
final int sessionId, final float[] inOutLanguageWeight) {
synchronized (mLock) {
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
blockOffensiveWords, additionalFeaturesOptions, sessionId, inOutLanguageWeight);
}
}

View File

@ -43,10 +43,10 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
final String prevWordForBigrams, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final float[] inOutLanguageWeight) {
final int sessionId, final float[] inOutLanguageWeight) {
synchronized (mLock) {
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, inOutLanguageWeight);
blockOffensiveWords, additionalFeaturesOptions, sessionId, inOutLanguageWeight);
}
}