am 79e2e9fa
: Merge "Add Dictionary.isInDictionary()."
* commit '79e2e9fa8c08ea1ad1b1e51f83bdd28fa88660dd': Add Dictionary.isInDictionary().
This commit is contained in:
commit
e3d55cc5b6
12 changed files with 38 additions and 49 deletions
|
@ -345,7 +345,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
return getFrequency(word) != NOT_A_PROBABILITY;
|
return getFrequency(word) != NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
import com.android.inputmethod.keyboard.ProximityInfo;
|
import com.android.inputmethod.keyboard.ProximityInfo;
|
||||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
|
||||||
|
@ -85,11 +86,19 @@ public abstract class Dictionary {
|
||||||
final int sessionId, final float[] inOutLanguageWeight);
|
final int sessionId, final float[] inOutLanguageWeight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given word occurs in the dictionary
|
* Checks if the given word has to be treated as a valid word. Please note that some
|
||||||
|
* dictionaries have entries that should be treated as invalid words.
|
||||||
* @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.
|
||||||
* @return true if the word exists, false otherwise
|
* @return true if the word is valid, false otherwise
|
||||||
*/
|
*/
|
||||||
abstract public boolean isValidWord(final String word);
|
public boolean isValidWord(final String word) {
|
||||||
|
return isInDictionary(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given word is in the dictionary regardless of it being valid or not.
|
||||||
|
*/
|
||||||
|
abstract public boolean isInDictionary(final String word);
|
||||||
|
|
||||||
public int getFrequency(final String word) {
|
public int getFrequency(final String word) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
|
@ -165,7 +174,7 @@ public abstract class Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(String word) {
|
public boolean isInDictionary(String word) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ public final class DictionaryCollection extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
for (int i = mDictionaries.size() - 1; i >= 0; --i)
|
||||||
if (mDictionaries.get(i).isValidWord(word)) return true;
|
if (mDictionaries.get(i).isInDictionary(word)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,7 +414,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
reloadDictionaryIfRequired();
|
reloadDictionaryIfRequired();
|
||||||
boolean lockAcquired = false;
|
boolean lockAcquired = false;
|
||||||
try {
|
try {
|
||||||
|
@ -424,10 +424,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
if (mBinaryDictionary == null) {
|
if (mBinaryDictionary == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isValidWordLocked(word);
|
return isInDictionaryLocked(word);
|
||||||
}
|
}
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Log.e(TAG, "Interrupted tryLock() in isValidWord().", e);
|
Log.e(TAG, "Interrupted tryLock() in isInDictionary().", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (lockAcquired) {
|
if (lockAcquired) {
|
||||||
mLock.readLock().unlock();
|
mLock.readLock().unlock();
|
||||||
|
@ -436,9 +436,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidWordLocked(final String word) {
|
protected boolean isInDictionaryLocked(final String word) {
|
||||||
if (mBinaryDictionary == null) return false;
|
if (mBinaryDictionary == null) return false;
|
||||||
return mBinaryDictionary.isValidWord(word);
|
return mBinaryDictionary.isInDictionary(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -590,20 +590,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement BinaryDictionary.isInDictionary().
|
|
||||||
@UsedForTesting
|
|
||||||
public boolean isInUnderlyingBinaryDictionaryForTests(final String word) {
|
|
||||||
mLock.readLock().lock();
|
|
||||||
try {
|
|
||||||
if (mBinaryDictionary != null && mDictType == Dictionary.TYPE_USER_HISTORY) {
|
|
||||||
return mBinaryDictionary.isValidWord(word);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
mLock.readLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
public void waitAllTasksForTests() {
|
public void waitAllTasksForTests() {
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||||
|
|
|
@ -66,10 +66,10 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
if (mLock.readLock().tryLock()) {
|
if (mLock.readLock().tryLock()) {
|
||||||
try {
|
try {
|
||||||
return mBinaryDictionary.isValidWord(word);
|
return mBinaryDictionary.isInDictionary(word);
|
||||||
} finally {
|
} finally {
|
||||||
mLock.readLock().unlock();
|
mLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,4 +80,10 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
|
||||||
/* package */ void runGCIfRequired() {
|
/* package */ void runGCIfRequired() {
|
||||||
runGCIfRequired(false /* mindsBlockByGC */);
|
runGCIfRequired(false /* mindsBlockByGC */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidWord(final String word) {
|
||||||
|
// Strings out of this dictionary should not be considered existing words.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,4 @@ public class PersonalizationDictionary extends DecayingExpandableBinaryDictionar
|
||||||
final Locale locale, final File dictFile) {
|
final Locale locale, final File dictFile) {
|
||||||
return PersonalizationHelper.getPersonalizationDictionary(context, locale);
|
return PersonalizationHelper.getPersonalizationDictionary(context, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidWord(final String word) {
|
|
||||||
// Strings out of this dictionary should not be considered existing words.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,12 +47,6 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
|
||||||
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidWord(final String word) {
|
|
||||||
// Strings out of this dictionary should not be considered existing words.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a word to the user history dictionary.
|
* Add a word to the user history dictionary.
|
||||||
*
|
*
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> {
|
||||||
return noSuggestions;
|
return noSuggestions;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
// This is never called. However if for some strange reason it ever gets
|
// This is never called. However if for some strange reason it ever gets
|
||||||
// called, returning true is less destructive (it will not underline the
|
// called, returning true is less destructive (it will not underline the
|
||||||
// word in red).
|
// word in red).
|
||||||
|
|
|
@ -47,9 +47,9 @@ public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsB
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.isValidWord(word);
|
return super.isInDictionary(word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,9 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidWord(final String word) {
|
public boolean isInDictionary(final String word) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return super.isValidWord(word);
|
return super.isInDictionary(word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
dict.waitAllTasksForTests();
|
dict.waitAllTasksForTests();
|
||||||
for (int i = 0; i < numberOfWords; ++i) {
|
for (int i = 0; i < numberOfWords; ++i) {
|
||||||
final String word = words.get(i);
|
final String word = words.get(i);
|
||||||
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertTrue(dict.isInDictionary(word));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// write to file.
|
// write to file.
|
||||||
|
@ -268,19 +268,19 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
DistracterFilter.EMPTY_DISTRACTER_FILTER);
|
DistracterFilter.EMPTY_DISTRACTER_FILTER);
|
||||||
prevWordsInfo = new PrevWordsInfo(word);
|
prevWordsInfo = new PrevWordsInfo(word);
|
||||||
dict.waitAllTasksForTests();
|
dict.waitAllTasksForTests();
|
||||||
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertTrue(dict.isInDictionary(word));
|
||||||
}
|
}
|
||||||
forcePassingShortTime();
|
forcePassingShortTime();
|
||||||
dict.runGCIfRequired();
|
dict.runGCIfRequired();
|
||||||
dict.waitAllTasksForTests();
|
dict.waitAllTasksForTests();
|
||||||
for (final String word : words) {
|
for (final String word : words) {
|
||||||
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertTrue(dict.isInDictionary(word));
|
||||||
}
|
}
|
||||||
forcePassingLongTime();
|
forcePassingLongTime();
|
||||||
dict.runGCIfRequired();
|
dict.runGCIfRequired();
|
||||||
dict.waitAllTasksForTests();
|
dict.waitAllTasksForTests();
|
||||||
for (final String word : words) {
|
for (final String word : words) {
|
||||||
assertFalse(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertFalse(dict.isInDictionary(word));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue