From bf1cf1b91a97d61de97792cd38fe1b8edde1aeaa Mon Sep 17 00:00:00 2001 From: Helium314 Date: Tue, 24 Oct 2023 16:07:03 +0200 Subject: [PATCH] fix adding words to personal dictionary, remove logging --- .../latin/DictionaryFacilitatorImpl.java | 43 ++++++++++--------- .../latin/inputlogic/InputLogic.java | 1 - 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java index ec455a297..486f79ae3 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/DictionaryFacilitatorImpl.java @@ -654,27 +654,11 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { // main and secondary isValid provided to avoid duplicate lookups private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, boolean[] validWordForDictionary) { - // we need one clearly preferred group to assign it to the correct language - int highestGroup = -1; - // require confidence to be MAX_CONFIDENCE, to be sure about language - // since the word is unknown, confidence has already been reduced, but after a first miss - // confidence is actually reduced to MAX_CONFIDENCE if it was larger - int highestGroupConfidence = DictionaryGroup.MAX_CONFIDENCE - 1; - for (int i = 0; i < mDictionaryGroups.size(); i ++) { - final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i); - if (dictionaryGroup.mConfidence > highestGroupConfidence) { - highestGroup = i; - highestGroupConfidence = dictionaryGroup.mConfidence; - } else if (dictionaryGroup.mConfidence == highestGroupConfidence) { - highestGroup = -1; - } - } - // no preferred group or word is valid -> do nothing - if (highestGroup == -1) return; - final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(highestGroup); + final DictionaryGroup dictionaryGroup = getClearlyPreferredDictionaryGroupOrNull(); + if (dictionaryGroup == null) return; if (validWordForDictionary == null ? isValidWord(suggestion, ALL_DICTIONARY_TYPES, dictionaryGroup) - : validWordForDictionary[highestGroup] + : validWordForDictionary[mDictionaryGroups.indexOf(dictionaryGroup)] ) return; @@ -690,7 +674,6 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { UserDictionary.Words.addWord(userDict.mContext, suggestion, 250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale)); } - } private void putWordIntoValidSpellingWordCache( @@ -788,6 +771,26 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { return dictGroup; } + private DictionaryGroup getClearlyPreferredDictionaryGroupOrNull() { + // we want one clearly preferred group and return null otherwise + if (mDictionaryGroups.size() == 1) + return mDictionaryGroups.get(0); + // that preferred group should have at least MAX_CONFIDENCE + int highestGroup = -1; + int highestGroupConfidence = DictionaryGroup.MAX_CONFIDENCE - 1; + for (int i = 0; i < mDictionaryGroups.size(); i ++) { + final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i); + if (dictionaryGroup.mConfidence > highestGroupConfidence) { + highestGroup = i; + highestGroupConfidence = dictionaryGroup.mConfidence; + } else if (dictionaryGroup.mConfidence == highestGroupConfidence) { + highestGroup = -1; // unset group on a tie + } + } + if (highestGroup == -1) return null; + return mDictionaryGroups.get(highestGroup); + } + private void removeWord(final String dictName, final String word) { final ExpandableBinaryDictionary dictionary = getCurrentlyPreferredDictionaryGroup().getSubDict(dictName); if (dictionary != null) { diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java index 6fffa090d..12b98dcd9 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java @@ -434,7 +434,6 @@ public final class InputLogic { mWordBeingCorrectedByCursor = null; mJustRevertedACommit = false; final Event processedEvent; - Log.i("test", "cp "+event.getMCodePoint()+", code "+event.getMKeyCode()); if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL // only use the Hangul chain if codepoint may actually be Hangul // todo: this whole hangul-related logic should probably be somewhere else