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
This commit is contained in:
Helium314 2024-08-27 19:52:10 +02:00
parent 6f71e577d3
commit c96326a256

View file

@ -727,20 +727,21 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
// we want one clearly preferred group and return null otherwise // we want one clearly preferred group and return null otherwise
if (mDictionaryGroups.size() == 1) if (mDictionaryGroups.size() == 1)
return mDictionaryGroups.get(0); return mDictionaryGroups.get(0);
// that preferred group should have at least MAX_CONFIDENCE // that preferred group should have at least MAX_CONFIDENCE, and all others should have 0 (we want to be really sure!)
int highestGroup = -1; int preferredGroup = -1;
int highestGroupConfidence = DictionaryGroup.MAX_CONFIDENCE - 1;
for (int i = 0; i < mDictionaryGroups.size(); i ++) { for (int i = 0; i < mDictionaryGroups.size(); i ++) {
final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i); final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i);
if (dictionaryGroup.mConfidence > highestGroupConfidence) { if (dictionaryGroup.mConfidence == 0) continue;
highestGroup = i; if (dictionaryGroup.mConfidence >= DictionaryGroup.MAX_CONFIDENCE && preferredGroup == -1) {
highestGroupConfidence = dictionaryGroup.mConfidence; preferredGroup = i;
} else if (dictionaryGroup.mConfidence == highestGroupConfidence) { continue;
highestGroup = -1; // unset group on a tie
} }
// 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; if (preferredGroup == -1) return null;
return mDictionaryGroups.get(highestGroup); return mDictionaryGroups.get(preferredGroup);
} }
private void removeWord(final String dictName, final String word) { private void removeWord(final String dictName, final String word) {