diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Dictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Dictionary.java | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 0742fbde9..b55ed125f 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -57,6 +58,8 @@ public abstract class Dictionary { public static final String TYPE_USER_HISTORY = "history"; // Personalization dictionary. public static final String TYPE_PERSONALIZATION = "personalization"; + // Contextual dictionary. + public static final String TYPE_CONTEXTUAL = "contextual"; public final String mDictType; public Dictionary(final String dictType) { @@ -67,43 +70,44 @@ public abstract class Dictionary { * Searches for suggestions for a given context. For the moment the context is only the * previous word. * @param composer the key sequence to match with coordinate info, as a WordComposer - * @param prevWord the previous word, or null if none + * @param prevWordsInfo the information of previous words. * @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. * @return the list of suggestions (possibly null if none) */ - // TODO: pass more context than just the previous word, to enable better suggestions (n-gram - // and more) abstract public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, - final String prevWord, final ProximityInfo proximityInfo, + final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, 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 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. + * @return true if the word is valid, false otherwise + */ + public boolean isValidWord(final String word) { + return isInDictionary(word); } /** - * Checks if the given word occurs in the dictionary - * @param word the word to search for. The search should be case-insensitive. - * @return true if the word exists, false otherwise + * Checks if the given word is in the dictionary regardless of it being valid or not. */ - abstract public boolean isValidWord(final String word); + abstract public boolean isInDictionary(final String word); public int getFrequency(final String word) { return NOT_A_PROBABILITY; } + public int getMaxFrequencyOfExactMatches(final String word) { + return NOT_A_PROBABILITY; + } + /** * Compares the contents of the character array with the typed word and returns true if they * are the same. @@ -163,14 +167,14 @@ public abstract class Dictionary { @Override public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, - final String prevWord, final ProximityInfo proximityInfo, + final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo, final boolean blockOffensiveWords, final int[] additionalFeaturesOptions, - final float[] inOutLanguageWeight) { + final int sessionId, final float[] inOutLanguageWeight) { return null; } @Override - public boolean isValidWord(String word) { + public boolean isInDictionary(String word) { return false; } } |