fix issues with adding words to personal dictionary

This commit is contained in:
Helium314 2023-07-08 09:11:22 +02:00
parent 2439791322
commit f498d14e3b
2 changed files with 35 additions and 28 deletions

View file

@ -57,6 +57,7 @@ Plan / to do:
* ~license issues, require using an external library~ * ~license issues, require using an external library~
* re-consider preferring lowercase word for typed history in some cases (DictionaryFacilitatorImpl.addWordToUserHistory) * re-consider preferring lowercase word for typed history in some cases (DictionaryFacilitatorImpl.addWordToUserHistory)
* ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~ * ~move/copy _use contacts_ setting from well hidden spell checker settings to _text correction_ settings~
* add emojis to user history, to be used for next word suggestions
----- -----

View file

@ -681,7 +681,31 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
&& Settings.getInstance().getCurrent().mAddToPersonalDictionary && Settings.getInstance().getCurrent().mAddToPersonalDictionary
&& (mSecondaryDictionaryGroup == null || mDictionaryGroup.mConfidence != mSecondaryDictionaryGroup.mConfidence) && (mSecondaryDictionaryGroup == null || mDictionaryGroup.mConfidence != mSecondaryDictionaryGroup.mConfidence)
&& !wasAutoCapitalized && words.length == 1) { && !wasAutoCapitalized && words.length == 1) {
// user history always reports words as invalid, so we need to check isInDictionary instead addToPersonalDictionaryIfInvalidButInHistory(suggestion, validMainWord, validSecondaryWord);
}
NgramContext ngramContextForCurrentWord = ngramContext;
for (int i = 0; i < words.length; i++) {
final String currentWord = words[i];
final boolean wasCurrentWordAutoCapitalized = (i == 0) && wasAutoCapitalized;
// add to history for preferred dictionary group, to avoid mixing languages in history
addWordToUserHistory(getCurrentlyPreferredDictionaryGroup(), ngramContextForCurrentWord, currentWord,
wasCurrentWordAutoCapitalized, (int) timeStampInSeconds,
blockPotentiallyOffensive);
ngramContextForCurrentWord =
ngramContextForCurrentWord.getNextNgramContext(new WordInfo(currentWord));
// remove entered words from blacklist
if (mDictionaryGroup.blacklist.remove(currentWord))
removeWordFromBlacklistFile(currentWord, mDictionaryGroup.blacklistFileName);
if (mSecondaryDictionaryGroup != null && mSecondaryDictionaryGroup.blacklist.remove(currentWord))
removeWordFromBlacklistFile(currentWord, mSecondaryDictionaryGroup.blacklistFileName);
}
}
// main and secondary isValid provided to avoid duplicate lookups
private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, Boolean validMainWord, Boolean validSecondaryWord) {
// user history always reports words as invalid, so here we need to check isInDictionary instead
// also maybe a problem: words added to dictionaries (user and history) are apparently found // also maybe a problem: words added to dictionaries (user and history) are apparently found
// only after some delay. but this is not too bad, it just delays adding // only after some delay. but this is not too bad, it just delays adding
@ -709,25 +733,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
}); });
} }
}
NgramContext ngramContextForCurrentWord = ngramContext;
for (int i = 0; i < words.length; i++) {
final String currentWord = words[i];
final boolean wasCurrentWordAutoCapitalized = (i == 0) && wasAutoCapitalized;
// add to history for preferred dictionary group, to avoid mixing languages in history
addWordToUserHistory(getCurrentlyPreferredDictionaryGroup(), ngramContextForCurrentWord, currentWord,
wasCurrentWordAutoCapitalized, (int) timeStampInSeconds,
blockPotentiallyOffensive);
ngramContextForCurrentWord =
ngramContextForCurrentWord.getNextNgramContext(new WordInfo(currentWord));
// remove entered words from blacklist
if (mDictionaryGroup.blacklist.remove(currentWord))
removeWordFromBlacklistFile(currentWord, mDictionaryGroup.blacklistFileName);
if (mSecondaryDictionaryGroup != null && mSecondaryDictionaryGroup.blacklist.remove(currentWord))
removeWordFromBlacklistFile(currentWord, mSecondaryDictionaryGroup.blacklistFileName);
}
} }
private void putWordIntoValidSpellingWordCache( private void putWordIntoValidSpellingWordCache(