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
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) {