mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 06:52:57 +00:00
still adjust multilingual typing confidences on slow input connections
This commit is contained in:
parent
8d3a32bcb2
commit
228f859cbd
3 changed files with 34 additions and 21 deletions
|
@ -149,6 +149,8 @@ public interface DictionaryFacilitator {
|
|||
@NonNull final NgramContext ngramContext, final long timeStampInSeconds,
|
||||
final boolean blockPotentiallyOffensive);
|
||||
|
||||
void adjustConfidences(final String word, final boolean wasAutoCapitalized);
|
||||
|
||||
void unlearnFromUserHistory(final String word,
|
||||
@NonNull final NgramContext ngramContext, final long timeStampInSeconds,
|
||||
final int eventType);
|
||||
|
|
|
@ -610,21 +610,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
|||
// increase / decrease confidence if we have more than one dictionary group
|
||||
boolean[] validWordForDictionary; // store results to avoid unnecessary duplicate lookups
|
||||
if (mDictionaryGroups.size() > 1 && words.length == 1) { // ignore if more than a single word, this only happens with (badly working) spaceAwareGesture
|
||||
validWordForDictionary = new boolean[mDictionaryGroups.size()];
|
||||
// if suggestion was auto-capitalized, check against both the suggestion and the de-capitalized suggestion
|
||||
final String decapitalizedSuggestion;
|
||||
if (wasAutoCapitalized)
|
||||
decapitalizedSuggestion = suggestion.substring(0, 1).toLowerCase() + suggestion.substring(1);
|
||||
else
|
||||
decapitalizedSuggestion = suggestion;
|
||||
for (int i = 0; i < mDictionaryGroups.size(); i ++) {
|
||||
final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i);
|
||||
final boolean isValidWord = isValidWord(suggestion, ALL_DICTIONARY_TYPES, dictionaryGroup);
|
||||
if (isValidWord || (wasAutoCapitalized && isValidWord(decapitalizedSuggestion, ALL_DICTIONARY_TYPES, dictionaryGroup)))
|
||||
dictionaryGroup.increaseConfidence();
|
||||
else dictionaryGroup.decreaseConfidence();
|
||||
validWordForDictionary[i] = isValidWord;
|
||||
}
|
||||
validWordForDictionary = adjustConfidencesInternal(suggestion, wasAutoCapitalized);
|
||||
} else
|
||||
validWordForDictionary = null;
|
||||
|
||||
|
@ -656,6 +642,30 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void adjustConfidences(final String word, final boolean wasAutoCapitalized) {
|
||||
if (mDictionaryGroups.size() > 1 && !word.contains(Constants.WORD_SEPARATOR))
|
||||
adjustConfidencesInternal(word, wasAutoCapitalized);
|
||||
}
|
||||
|
||||
private boolean[] adjustConfidencesInternal(final String word, final boolean wasAutoCapitalized) {
|
||||
final boolean[] validWordForDictionary = new boolean[mDictionaryGroups.size()];
|
||||
// if suggestion was auto-capitalized, check against both the suggestion and the de-capitalized suggestion
|
||||
final String decapitalizedSuggestion;
|
||||
if (wasAutoCapitalized)
|
||||
decapitalizedSuggestion = word.substring(0, 1).toLowerCase() + word.substring(1);
|
||||
else
|
||||
decapitalizedSuggestion = word;
|
||||
for (int i = 0; i < mDictionaryGroups.size(); i ++) {
|
||||
final DictionaryGroup dictionaryGroup = mDictionaryGroups.get(i);
|
||||
final boolean isValidWord = isValidWord(word, ALL_DICTIONARY_TYPES, dictionaryGroup);
|
||||
if (isValidWord || (wasAutoCapitalized && isValidWord(decapitalizedSuggestion, ALL_DICTIONARY_TYPES, dictionaryGroup)))
|
||||
dictionaryGroup.increaseConfidence();
|
||||
else dictionaryGroup.decreaseConfidence();
|
||||
validWordForDictionary[i] = isValidWord;
|
||||
}
|
||||
return validWordForDictionary;
|
||||
}
|
||||
|
||||
// main and secondary isValid provided to avoid duplicate lookups
|
||||
private void addToPersonalDictionaryIfInvalidButInHistory(String suggestion, boolean[] validWordForDictionary) {
|
||||
final DictionaryGroup dictionaryGroup = getClearlyPreferredDictionaryGroupOrNull();
|
||||
|
|
|
@ -1535,20 +1535,21 @@ public final class InputLogic {
|
|||
// That's to avoid unintended additions in some sensitive fields, or fields that
|
||||
// expect to receive non-words.
|
||||
// mInputTypeNoAutoCorrect changed to !mShouldShowSuggestions because this was cancelling learning way too often
|
||||
if (!settingsValues.mInputAttributes.mShouldShowSuggestions || settingsValues.mIncognitoModeEnabled)
|
||||
if (!settingsValues.mInputAttributes.mShouldShowSuggestions || settingsValues.mIncognitoModeEnabled || TextUtils.isEmpty(suggestion))
|
||||
return;
|
||||
final boolean wasAutoCapitalized = mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps();
|
||||
final String word = stripWordSeparatorsFromEnd(suggestion, settingsValues);
|
||||
if (mConnection.hasSlowInputConnection()) {
|
||||
// Since we don't unlearn when the user backspaces on a slow InputConnection,
|
||||
// turn off learning to guard against adding typos that the user later deletes.
|
||||
Log.w(TAG, "Skipping learning due to slow InputConnection.");
|
||||
// but we still want to adjust confidences for multilingual typing
|
||||
mDictionaryFacilitator.adjustConfidences(word, wasAutoCapitalized);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(suggestion)) return;
|
||||
final boolean wasAutoCapitalized = mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps();
|
||||
final int timeStampInSeconds = (int)TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
|
||||
mDictionaryFacilitator.addToUserHistory(stripWordSeparatorsFromEnd(suggestion, settingsValues), wasAutoCapitalized,
|
||||
ngramContext, timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive);
|
||||
mDictionaryFacilitator.addToUserHistory(word, wasAutoCapitalized, ngramContext,
|
||||
timeStampInSeconds, settingsValues.mBlockPotentiallyOffensive);
|
||||
}
|
||||
|
||||
// strip word separators from end (may be necessary for urls, e.g. when the user has typed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue