diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 80 |
1 files changed, 19 insertions, 61 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index fa5a46fca..99a4d54d8 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -73,7 +73,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.List; import java.util.Locale; /** @@ -203,8 +202,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private boolean mShouldSwitchToLastSubtype = true; private UserDictionary mUserDictionary; - private UserBigramDictionary mUserBigramDictionary; - private UserUnigramDictionary mUserUnigramDictionary; + private UserHistoryDictionary mUserHistoryDictionary; private boolean mIsUserDictionaryAvailable; private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; @@ -528,13 +526,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar resetContactsDictionary(oldContactsDictionary); - mUserUnigramDictionary - = new UserUnigramDictionary(this, this, localeStr, Suggest.DIC_USER_UNIGRAM); - mSuggest.setUserUnigramDictionary(mUserUnigramDictionary); - - mUserBigramDictionary - = new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER_BIGRAM); - mSuggest.setUserBigramDictionary(mUserBigramDictionary); + mUserHistoryDictionary + = new UserHistoryDictionary(this, this, localeStr, Suggest.DIC_USER_HISTORY); + mSuggest.setUserHistoryDictionary(mUserHistoryDictionary); LocaleUtils.setSystemLocale(res, savedLocale); } @@ -776,8 +770,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); - if (mUserUnigramDictionary != null) mUserUnigramDictionary.flushPendingWrites(); - if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites(); + if (mUserHistoryDictionary != null) mUserHistoryDictionary.flushPendingWrites(); } private void onFinishInputViewInternal(boolean finishingInput) { @@ -923,7 +916,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - final List<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords = + final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); final SuggestedWords suggestedWords = new SuggestedWords( @@ -1114,8 +1107,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic != null) { ic.commitText(typedWord, 1); } - addToUserUnigramAndBigramDictionaries(typedWord, - UserUnigramDictionary.FREQUENCY_FOR_TYPED); + addToUserHistoryDictionary(typedWord); } updateSuggestions(); } @@ -1834,9 +1826,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mExpectingUpdateSelection = true; commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separatorCodePoint); - // Add the word to the user unigram dictionary if it's not a known word - addToUserUnigramAndBigramDictionaries(autoCorrection, - UserUnigramDictionary.FREQUENCY_FOR_TYPED); + // Add the word to the user history dictionary + addToUserHistoryDictionary(autoCorrection); if (!typedWord.equals(autoCorrection) && null != ic) { // This will make the correction flash for a short while as a visual clue // to the user that auto-correction happened. @@ -1895,13 +1886,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); - // Add the word to the auto dictionary if it's not a known word - if (index == 0) { - addToUserUnigramAndBigramDictionaries(suggestion, - UserUnigramDictionary.FREQUENCY_FOR_PICKED); - } else { - addToOnlyBigramDictionary(suggestion, 1); - } + // Add the word to the user history dictionary + addToUserHistoryDictionary(suggestion); mSpaceState = SPACE_STATE_PHANTOM; // TODO: is this necessary? mKeyboardSwitcher.updateShiftState(); @@ -2002,21 +1988,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setSuggestionStripShown(isSuggestionsStripVisible()); } - private void addToUserUnigramAndBigramDictionaries(CharSequence suggestion, - int frequencyDelta) { - checkAddToDictionary(suggestion, frequencyDelta, false); - } - - private void addToOnlyBigramDictionary(CharSequence suggestion, int frequencyDelta) { - checkAddToDictionary(suggestion, frequencyDelta, true); - } - - /** - * Adds to the UserBigramDictionary and/or UserUnigramDictionary - * @param selectedANotTypedWord true if it should be added to bigram dictionary if possible - */ - private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta, - boolean selectedANotTypedWord) { + private void addToUserHistoryDictionary(final CharSequence suggestion) { if (suggestion == null || suggestion.length() < 1) return; // Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be @@ -2027,30 +1999,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - if (null != mSuggest && null != mUserUnigramDictionary) { - final boolean selectedATypedWordAndItsInUserUnigramDic = - !selectedANotTypedWord && mUserUnigramDictionary.isValidWord(suggestion); - final boolean isValidWord = AutoCorrection.isValidWord( - mSuggest.getUnigramDictionaries(), suggestion, true); - final boolean needsToAddToUserUnigramDictionary = - selectedATypedWordAndItsInUserUnigramDic || !isValidWord; - if (needsToAddToUserUnigramDictionary) { - mUserUnigramDictionary.addWord(suggestion.toString(), frequencyDelta); - } - } - - if (mUserBigramDictionary != null) { - // We don't want to register as bigrams words separated by a separator. - // For example "I will, and you too" : we don't want the pair ("will" "and") to be - // a bigram. + if (mUserHistoryDictionary != null) { final InputConnection ic = getCurrentInputConnection(); + final CharSequence prevWord; if (null != ic) { - final CharSequence prevWord = - EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); - if (!TextUtils.isEmpty(prevWord)) { - mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString()); - } + prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); + } else { + prevWord = null; } + mUserHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(), + suggestion.toString()); } } |