From c96326a25679fff3d0aec1553d3dc940f799939f Mon Sep 17 00:00:00 2001 From: Helium314 Date: Tue, 27 Aug 2024 19:52:10 +0200 Subject: [PATCH] be a bit more strict when determining a clearly preferred language in multilingual typing should somewhat reduce addition of unwanted words to personal dictionary when auto-add is enabled --- .../latin/DictionaryFacilitatorImpl.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/DictionaryFacilitatorImpl.java b/app/src/main/java/helium314/keyboard/latin/DictionaryFacilitatorImpl.java index cfec22ec4..c6e5809f3 100644 --- a/app/src/main/java/helium314/keyboard/latin/DictionaryFacilitatorImpl.java +++ b/app/src/main/java/helium314/keyboard/latin/DictionaryFacilitatorImpl.java @@ -727,20 +727,21 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { // 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; + // that preferred group should have at least MAX_CONFIDENCE, and all others should have 0 (we want to be really sure!) + int preferredGroup = -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 (dictionaryGroup.mConfidence == 0) continue; + if (dictionaryGroup.mConfidence >= DictionaryGroup.MAX_CONFIDENCE && preferredGroup == -1) { + preferredGroup = i; + continue; } + // either we have 2 groups with high confidence, or a group with low but non-0 confidence + // in either case, we're not sure enough and return null + return null; } - if (highestGroup == -1) return null; - return mDictionaryGroups.get(highestGroup); + if (preferredGroup == -1) return null; + return mDictionaryGroups.get(preferredGroup); } private void removeWord(final String dictName, final String word) {