mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-03 21:24:46 +00:00
fix adding words to personal dictionary, remove logging
This commit is contained in:
parent
4ec8ff343d
commit
bf1cf1b91a
2 changed files with 23 additions and 21 deletions
|
@ -654,27 +654,11 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
|
|
||||||
// main and secondary isValid provided to avoid duplicate lookups
|
// main and secondary isValid provided to avoid duplicate lookups
|
||||||
private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, boolean[] validWordForDictionary) {
|
private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, boolean[] validWordForDictionary) {
|
||||||
// we need one clearly preferred group to assign it to the correct language
|
final DictionaryGroup dictionaryGroup = getClearlyPreferredDictionaryGroupOrNull();
|
||||||
int highestGroup = -1;
|
if (dictionaryGroup == null) return;
|
||||||
// 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);
|
|
||||||
if (validWordForDictionary == null
|
if (validWordForDictionary == null
|
||||||
? isValidWord(suggestion, ALL_DICTIONARY_TYPES, dictionaryGroup)
|
? isValidWord(suggestion, ALL_DICTIONARY_TYPES, dictionaryGroup)
|
||||||
: validWordForDictionary[highestGroup]
|
: validWordForDictionary[mDictionaryGroups.indexOf(dictionaryGroup)]
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -690,7 +674,6 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
UserDictionary.Words.addWord(userDict.mContext, suggestion,
|
UserDictionary.Words.addWord(userDict.mContext, suggestion,
|
||||||
250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale));
|
250 /*FREQUENCY_FOR_USER_DICTIONARY_ADDS*/, null, dictionaryGroup.mLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putWordIntoValidSpellingWordCache(
|
private void putWordIntoValidSpellingWordCache(
|
||||||
|
@ -788,6 +771,26 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
||||||
return dictGroup;
|
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) {
|
private void removeWord(final String dictName, final String word) {
|
||||||
final ExpandableBinaryDictionary dictionary = getCurrentlyPreferredDictionaryGroup().getSubDict(dictName);
|
final ExpandableBinaryDictionary dictionary = getCurrentlyPreferredDictionaryGroup().getSubDict(dictName);
|
||||||
if (dictionary != null) {
|
if (dictionary != null) {
|
||||||
|
|
|
@ -434,7 +434,6 @@ public final class InputLogic {
|
||||||
mWordBeingCorrectedByCursor = null;
|
mWordBeingCorrectedByCursor = null;
|
||||||
mJustRevertedACommit = false;
|
mJustRevertedACommit = false;
|
||||||
final Event processedEvent;
|
final Event processedEvent;
|
||||||
Log.i("test", "cp "+event.getMCodePoint()+", code "+event.getMKeyCode());
|
|
||||||
if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL
|
if (currentKeyboardScriptId == ScriptUtils.SCRIPT_HANGUL
|
||||||
// only use the Hangul chain if codepoint may actually be Hangul
|
// only use the Hangul chain if codepoint may actually be Hangul
|
||||||
// todo: this whole hangul-related logic should probably be somewhere else
|
// todo: this whole hangul-related logic should probably be somewhere else
|
||||||
|
|
Loading…
Add table
Reference in a new issue