parent
b30d2185f2
commit
f5943153ad
|
@ -109,15 +109,14 @@ public class BinaryDictionary extends Dictionary {
|
||||||
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
||||||
if (composer.size() <= 1) {
|
if (composer.size() <= 1) {
|
||||||
return TextUtils.isEmpty(prevWord) ? null : getBigrams(composer, prevWord);
|
return TextUtils.isEmpty(prevWord) ? null : getBigramsInternal(composer, prevWord);
|
||||||
} else {
|
} else {
|
||||||
return getWords(composer, prevWord, proximityInfo);
|
return getWordsInternal(composer, prevWord, proximityInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename this to getBigramsInternal, then move to native code
|
// TODO: move to native code
|
||||||
@Override
|
private ArrayList<SuggestedWordInfo> getBigramsInternal(final WordComposer codes,
|
||||||
protected ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
|
|
||||||
final CharSequence previousWord) {
|
final CharSequence previousWord) {
|
||||||
if (mNativeDict == 0) return null;
|
if (mNativeDict == 0) return null;
|
||||||
|
|
||||||
|
@ -154,10 +153,9 @@ public class BinaryDictionary extends Dictionary {
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rename this to getWordsInternal, then move to native code
|
// TODO: move to native code
|
||||||
// proximityInfo and/or prevWordForBigrams may not be null.
|
// proximityInfo and/or prevWordForBigrams may not be null.
|
||||||
@Override
|
private ArrayList<SuggestedWordInfo> getWordsInternal(final WordComposer codes,
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars,
|
final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars,
|
||||||
mScores, mSpaceIndices);
|
mScores, mSpaceIndices);
|
||||||
|
|
|
@ -64,28 +64,6 @@ public abstract class Dictionary {
|
||||||
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo);
|
final CharSequence prevWord, final ProximityInfo proximityInfo);
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for words in the dictionary that match the characters in the composer. Matched
|
|
||||||
* words are returned as an ArrayList.
|
|
||||||
* @param composer the key sequence to match with coordinate info, as a WordComposer
|
|
||||||
* @param prevWordForBigrams the previous word, or null if none
|
|
||||||
* @param proximityInfo the object for key proximity. May be ignored by some implementations.
|
|
||||||
* @return the list of suggestions
|
|
||||||
*/
|
|
||||||
// TODO: remove this
|
|
||||||
abstract protected ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for pairs in the bigram dictionary that matches the previous word.
|
|
||||||
* @param composer the key sequence to match
|
|
||||||
* @param previousWord the word before
|
|
||||||
* @return the list of suggestions
|
|
||||||
*/
|
|
||||||
// TODO: remove this
|
|
||||||
abstract protected ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer,
|
|
||||||
final CharSequence previousWord);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given word occurs in the dictionary
|
* Checks if the given word occurs in the dictionary
|
||||||
* @param word the word to search for. The search should be case-insensitive.
|
* @param word the word to search for. The search should be case-insensitive.
|
||||||
|
|
|
@ -73,46 +73,6 @@ public class DictionaryCollection extends Dictionary {
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this
|
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
|
||||||
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).getWords(composer,
|
|
||||||
prevWordForBigrams, proximityInfo);
|
|
||||||
if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>();
|
|
||||||
final int length = dictionaries.size();
|
|
||||||
for (int i = 0; i < length; ++ i) {
|
|
||||||
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getWords(composer,
|
|
||||||
prevWordForBigrams, proximityInfo);
|
|
||||||
if (null != sugg) suggestions.addAll(sugg);
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove this
|
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer,
|
|
||||||
final CharSequence previousWord) {
|
|
||||||
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).getBigrams(composer,
|
|
||||||
previousWord);
|
|
||||||
if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>();
|
|
||||||
final int length = dictionaries.size();
|
|
||||||
for (int i = 0; i < length; ++ i) {
|
|
||||||
final ArrayList<SuggestedWordInfo> sugg =
|
|
||||||
dictionaries.get(i).getBigrams(composer, previousWord);
|
|
||||||
if (null != sugg) suggestions.addAll(sugg);
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(CharSequence word) {
|
public boolean isValidWord(CharSequence word) {
|
||||||
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
||||||
|
|
|
@ -16,7 +16,6 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.ProximityInfo;
|
import com.android.inputmethod.keyboard.ProximityInfo;
|
||||||
|
@ -208,52 +207,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this
|
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
|
||||||
asyncReloadDictionaryIfRequired();
|
|
||||||
return getWordsInner(codes, prevWordForBigrams, proximityInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
|
||||||
// Ensure that there are no concurrent calls to getWords. If there are, do nothing and
|
|
||||||
// return.
|
|
||||||
if (mLocalDictionaryController.tryLock()) {
|
|
||||||
try {
|
|
||||||
if (mBinaryDictionary != null) {
|
|
||||||
return mBinaryDictionary.getWords(codes, prevWordForBigrams, proximityInfo);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
mLocalDictionaryController.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove this
|
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
|
|
||||||
final CharSequence previousWord) {
|
|
||||||
asyncReloadDictionaryIfRequired();
|
|
||||||
return getBigramsInner(codes, previousWord);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ArrayList<SuggestedWordInfo> getBigramsInner(final WordComposer codes,
|
|
||||||
final CharSequence previousWord) {
|
|
||||||
if (mLocalDictionaryController.tryLock()) {
|
|
||||||
try {
|
|
||||||
if (mBinaryDictionary != null) {
|
|
||||||
return mBinaryDictionary.getBigrams(codes, previousWord);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
mLocalDictionaryController.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final CharSequence word) {
|
public boolean isValidWord(final CharSequence word) {
|
||||||
asyncReloadDictionaryIfRequired();
|
asyncReloadDictionaryIfRequired();
|
||||||
|
|
|
@ -266,19 +266,6 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this
|
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
|
||||||
if (reloadDictionaryIfRequired()) return null;
|
|
||||||
if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestions =
|
|
||||||
getWordsInner(codes, prevWordForBigrams, proximityInfo);
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This reloads the dictionary if required, and returns whether it's currently updating its
|
// This reloads the dictionary if required, and returns whether it's currently updating its
|
||||||
// contents or not.
|
// contents or not.
|
||||||
// @VisibleForTesting
|
// @VisibleForTesting
|
||||||
|
@ -290,17 +277,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this
|
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
|
||||||
@Override
|
|
||||||
protected ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
|
|
||||||
final CharSequence previousWord) {
|
|
||||||
if (reloadDictionaryIfRequired()) return null;
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
|
||||||
runBigramReverseLookUp(previousWord, suggestions);
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
|
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
|
||||||
mInputLength = codes.size();
|
mInputLength = codes.size();
|
||||||
|
|
|
@ -32,10 +32,10 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
|
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return getWordsInner(codes, prevWordForBigrams, proximityInfo);
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,10 +35,10 @@ public class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionar
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
|
public synchronized ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer codes,
|
||||||
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
|
||||||
syncReloadDictionaryIfRequired();
|
syncReloadDictionaryIfRequired();
|
||||||
return getWordsInner(codes, prevWordForBigrams, proximityInfo);
|
return super.getSuggestions(codes, prevWordForBigrams, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -161,10 +161,10 @@ public class UserHistoryDictionary extends ExpandableDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
|
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
||||||
// User history unigrams are not used at this moment. Implement this method to make them
|
// Inhibit suggestions (not predictions) for user history for now. Removing this method
|
||||||
// useful.
|
// is enough to use it through the standard ExpandableDictionary way.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,10 +92,9 @@ public class WhitelistDictionary extends ExpandableDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
|
public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
|
||||||
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
final CharSequence prevWord, final ProximityInfo proximityInfo) {
|
||||||
// Whitelist does not supply suggestions (actually it should not even implement the
|
// Whitelist does not supply any suggestions or predictions.
|
||||||
// Dictionary interface, as it responds to none of it, but it does for legacy reasons)
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue