Pass the previous word to getSuggestions

This is a preparative change to bug#6313806

Change-Id: I1be9ec49b21005c1f45ce459fa93712bc74ef3f0
This commit is contained in:
Jean Chalard 2012-04-17 12:43:53 +09:00
parent 9c2a96aa6c
commit ac27e4544b
11 changed files with 39 additions and 28 deletions

View file

@ -135,11 +135,12 @@ public class BinaryDictionary extends Dictionary {
} }
} }
// proximityInfo may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
@Override @Override
public void getWords(final WordComposer codes, final WordCallback callback, public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams,
final ProximityInfo proximityInfo) { final WordCallback callback, final ProximityInfo proximityInfo) {
final int count = getSuggestions(codes, proximityInfo, mOutputChars, mScores); final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars,
mScores);
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (mScores[j] < 1) break; if (mScores[j] < 1) break;
@ -161,7 +162,8 @@ public class BinaryDictionary extends Dictionary {
// proximityInfo may not be null. // proximityInfo may not be null.
/* package for test */ int getSuggestions(final WordComposer codes, /* package for test */ int getSuggestions(final WordComposer codes,
final ProximityInfo proximityInfo, char[] outputChars, int[] scores) { final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo,
char[] outputChars, int[] scores) {
if (!isValidDictionary()) return -1; if (!isValidDictionary()) return -1;
final int codesSize = codes.size(); final int codesSize = codes.size();
@ -175,6 +177,7 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(outputChars, (char) 0); Arrays.fill(outputChars, (char) 0);
Arrays.fill(scores, 0); Arrays.fill(scores, 0);
// TODO: pass the previous word to native code
return getSuggestionsNative( return getSuggestionsNative(
mNativeDict, proximityInfo.getNativeProximityInfo(), mNativeDict, proximityInfo.getNativeProximityInfo(),
codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize, codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,

View file

@ -61,11 +61,13 @@ public abstract class Dictionary {
* Searches for words in the dictionary that match the characters in the composer. Matched * Searches for words in the dictionary that match the characters in the composer. Matched
* words are added through the callback object. * words are added through the callback object.
* @param composer the key sequence to match * @param composer the key sequence to match
* @param prevWordForBigrams the previous word, or null if none
* @param callback the callback object to send matched words to as possible candidates * @param callback the callback object to send matched words to as possible candidates
* @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.
* @see WordCallback#addWord(char[], int, int, int, int, int) * @see WordCallback#addWord(char[], int, int, int, int, int)
*/ */
abstract public void getWords(final WordComposer composer, final WordCallback callback, abstract public void getWords(final WordComposer composer,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo); final ProximityInfo proximityInfo);
/** /**

View file

@ -50,10 +50,10 @@ public class DictionaryCollection extends Dictionary {
} }
@Override @Override
public void getWords(final WordComposer composer, final WordCallback callback, public void getWords(final WordComposer composer, final CharSequence prevWordForBigrams,
final ProximityInfo proximityInfo) { final WordCallback callback, final ProximityInfo proximityInfo) {
for (final Dictionary dict : mDictionaries) for (final Dictionary dict : mDictionaries)
dict.getWords(composer, callback, proximityInfo); dict.getWords(composer, prevWordForBigrams, callback, proximityInfo);
} }
@Override @Override

View file

@ -173,20 +173,21 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
} }
@Override @Override
public void getWords(final WordComposer codes, final WordCallback callback, public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams,
final ProximityInfo proximityInfo) { final WordCallback callback, final ProximityInfo proximityInfo) {
asyncReloadDictionaryIfRequired(); asyncReloadDictionaryIfRequired();
getWordsInner(codes, callback, proximityInfo); getWordsInner(codes, prevWordForBigrams, callback, proximityInfo);
} }
protected final void getWordsInner(final WordComposer codes, final WordCallback callback, protected final void getWordsInner(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo) {
// Ensure that there are no concurrent calls to getWords. If there are, do nothing and // Ensure that there are no concurrent calls to getWords. If there are, do nothing and
// return. // return.
if (mLocalDictionaryController.tryLock()) { if (mLocalDictionaryController.tryLock()) {
try { try {
if (mBinaryDictionary != null) { if (mBinaryDictionary != null) {
mBinaryDictionary.getWords(codes, callback, proximityInfo); mBinaryDictionary.getWords(codes, prevWordForBigrams, callback, proximityInfo);
} }
} finally { } finally {
mLocalDictionaryController.unlock(); mLocalDictionaryController.unlock();

View file

@ -192,8 +192,8 @@ public class ExpandableDictionary extends Dictionary {
} }
@Override @Override
public void getWords(final WordComposer codes, final WordCallback callback, public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams,
final ProximityInfo proximityInfo) { final WordCallback callback, final ProximityInfo proximityInfo) {
synchronized (mUpdatingLock) { synchronized (mUpdatingLock) {
// If we need to update, start off a background task // If we need to update, start off a background task
if (mRequiresReload) startDictionaryLoadingTaskLocked(); if (mRequiresReload) startDictionaryLoadingTaskLocked();
@ -203,10 +203,11 @@ public class ExpandableDictionary extends Dictionary {
if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) { if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
return; return;
} }
getWordsInner(codes, callback, proximityInfo); getWordsInner(codes, prevWordForBigrams, callback, proximityInfo);
} }
protected final void getWordsInner(final WordComposer codes, final WordCallback callback, protected final void getWordsInner(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
@SuppressWarnings("unused") final ProximityInfo proximityInfo) { @SuppressWarnings("unused") final ProximityInfo proximityInfo) {
mInputLength = codes.size(); mInputLength = codes.size();
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; if (mCodes.length < mInputLength) mCodes = new int[mInputLength][];

View file

@ -340,7 +340,7 @@ public class Suggest implements Dictionary.WordCallback {
if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST)) if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
continue; continue;
final Dictionary dictionary = mUnigramDictionaries.get(key); final Dictionary dictionary = mUnigramDictionaries.get(key);
dictionary.getWords(wordComposerForLookup, this, proximityInfo); dictionary.getWords(wordComposerForLookup, prevWordForBigram, this, proximityInfo);
} }
} }

View file

@ -30,10 +30,11 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD
} }
@Override @Override
public synchronized void getWords(final WordComposer codes, final WordCallback callback, public synchronized void getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo) {
syncReloadDictionaryIfRequired(); syncReloadDictionaryIfRequired();
getWordsInner(codes, callback, proximityInfo); getWordsInner(codes, prevWordForBigrams, callback, proximityInfo);
} }
@Override @Override

View file

@ -29,10 +29,11 @@ public class SynchronouslyLoadedContactsDictionary extends ContactsDictionary {
} }
@Override @Override
public synchronized void getWords(final WordComposer codes, final WordCallback callback, public synchronized void getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo) {
blockingReloadDictionaryIfRequired(); blockingReloadDictionaryIfRequired();
getWordsInner(codes, callback, proximityInfo); getWordsInner(codes, prevWordForBigrams, callback, proximityInfo);
} }
@Override @Override

View file

@ -32,10 +32,11 @@ public class SynchronouslyLoadedUserDictionary extends UserDictionary {
} }
@Override @Override
public synchronized void getWords(final WordComposer codes, final WordCallback callback, public synchronized void getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo) {
blockingReloadDictionaryIfRequired(); blockingReloadDictionaryIfRequired();
getWordsInner(codes, callback, proximityInfo); getWordsInner(codes, prevWordForBigrams, callback, proximityInfo);
} }
@Override @Override

View file

@ -174,9 +174,10 @@ public class UserDictionary extends ExpandableDictionary {
} }
@Override @Override
public synchronized void getWords(final WordComposer codes, final WordCallback callback, public synchronized void getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo) {
super.getWords(codes, callback, proximityInfo); super.getWords(codes, prevWordForBigrams, callback, proximityInfo);
} }
@Override @Override

View file

@ -588,7 +588,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
try { try {
dictInfo = mDictionaryPool.takeOrGetNull(); dictInfo = mDictionaryPool.takeOrGetNull();
if (null == dictInfo) return getNotInDictEmptySuggestions(); if (null == dictInfo) return getNotInDictEmptySuggestions();
dictInfo.mDictionary.getWords(composer, suggestionsGatherer, dictInfo.mDictionary.getWords(composer, null, suggestionsGatherer,
dictInfo.mProximityInfo); dictInfo.mProximityInfo);
isInDict = dictInfo.mDictionary.isValidWord(text); isInDict = dictInfo.mDictionary.isValidWord(text);
if (!isInDict && CAPITALIZE_NONE != capitalizeType) { if (!isInDict && CAPITALIZE_NONE != capitalizeType) {