mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 17:00:30 +00:00
don't always ignore dictionary shortcuts, but only if the alternative word has been used in this ngram context
This commit is contained in:
parent
801d82aa8a
commit
50383bcbe5
1 changed files with 25 additions and 7 deletions
|
@ -21,7 +21,9 @@ import android.text.TextUtils;
|
||||||
import org.dslul.openboard.inputmethod.keyboard.Keyboard;
|
import org.dslul.openboard.inputmethod.keyboard.Keyboard;
|
||||||
import org.dslul.openboard.inputmethod.keyboard.KeyboardId;
|
import org.dslul.openboard.inputmethod.keyboard.KeyboardId;
|
||||||
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
import org.dslul.openboard.inputmethod.latin.common.ComposedData;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||||
|
import org.dslul.openboard.inputmethod.latin.common.InputPointers;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
|
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
|
||||||
import org.dslul.openboard.inputmethod.latin.settings.SettingsValuesForSuggestion;
|
import org.dslul.openboard.inputmethod.latin.settings.SettingsValuesForSuggestion;
|
||||||
|
@ -187,7 +189,7 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int firstOcurrenceOfTypedWordInSuggestions =
|
final int firstOccurrenceOfTypedWordInSuggestions =
|
||||||
SuggestedWordInfo.removeDupsAndTypedWord(typedWordString, suggestionsContainer);
|
SuggestedWordInfo.removeDupsAndTypedWord(typedWordString, suggestionsContainer);
|
||||||
|
|
||||||
final SuggestedWordInfo whitelistedWordInfo =
|
final SuggestedWordInfo whitelistedWordInfo =
|
||||||
|
@ -241,7 +243,7 @@ public final class Suggest {
|
||||||
} else {
|
} else {
|
||||||
final SuggestedWordInfo firstSuggestion = suggestionResults.first();
|
final SuggestedWordInfo firstSuggestion = suggestionResults.first();
|
||||||
if (suggestionResults.mFirstSuggestionExceedsConfidenceThreshold
|
if (suggestionResults.mFirstSuggestionExceedsConfidenceThreshold
|
||||||
&& firstOcurrenceOfTypedWordInSuggestions != 0) {
|
&& firstOccurrenceOfTypedWordInSuggestions != 0) {
|
||||||
// todo: mFirstSuggestionExceedsConfidenceThreshold is always false, so currently
|
// todo: mFirstSuggestionExceedsConfidenceThreshold is always false, so currently
|
||||||
// this branch is useless. remove the related logic, or actually use it
|
// this branch is useless. remove the related logic, or actually use it
|
||||||
hasAutoCorrection = true;
|
hasAutoCorrection = true;
|
||||||
|
@ -254,10 +256,26 @@ public final class Suggest {
|
||||||
// form to allow auto-correcting to it in this language. For details of how this
|
// form to allow auto-correcting to it in this language. For details of how this
|
||||||
// is determined, see #isAllowedByAutoCorrectionWithSpaceFilter.
|
// is determined, see #isAllowedByAutoCorrectionWithSpaceFilter.
|
||||||
// TODO: this should not have its own logic here but be handled by the dictionary.
|
// TODO: this should not have its own logic here but be handled by the dictionary.
|
||||||
if (typedWordFirstOccurrenceWordInfo != null && typedWordFirstOccurrenceWordInfo.mScore > 1000000)
|
final boolean allowed = isAllowedByAutoCorrectionWithSpaceFilter(firstSuggestion);
|
||||||
hasAutoCorrection = false; // do not autocorrect if typed word has a good score, todo: the threshold may need tuning
|
// todo: the threshold (currently 1000000) may need tuning
|
||||||
else
|
if (allowed && typedWordFirstOccurrenceWordInfo != null && typedWordFirstOccurrenceWordInfo.mScore > 1000000) {
|
||||||
hasAutoCorrection = isAllowedByAutoCorrectionWithSpaceFilter(firstSuggestion);
|
// typed word is valid and has good score
|
||||||
|
// do not auto-correct if typed word is a prediction from ngram context alone
|
||||||
|
// todo: maybe instead check for both words, and check which one is better
|
||||||
|
// more complicated, could be better, but could also give unexpected results
|
||||||
|
boolean typedWordOccursInEmptyWordSuggestions = false;
|
||||||
|
final SuggestionResults emptyWordSuggestions = mDictionaryFacilitator.getSuggestionResults(
|
||||||
|
new ComposedData(new InputPointers(1), false, ""), ngramContext,
|
||||||
|
keyboard, settingsValuesForSuggestion, SESSION_ID_TYPING, inputStyleIfNotPrediction);
|
||||||
|
for (SuggestedWordInfo i : emptyWordSuggestions) {
|
||||||
|
if (typedWordString.equals(i.getWord())) {
|
||||||
|
typedWordOccursInEmptyWordSuggestions = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hasAutoCorrection = !typedWordOccursInEmptyWordSuggestions;
|
||||||
|
} else
|
||||||
|
hasAutoCorrection = allowed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +307,7 @@ public final class Suggest {
|
||||||
inputStyle = inputStyleIfNotPrediction;
|
inputStyle = inputStyleIfNotPrediction;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isTypedWordValid = firstOcurrenceOfTypedWordInSuggestions > -1
|
final boolean isTypedWordValid = firstOccurrenceOfTypedWordInSuggestions > -1
|
||||||
|| (!resultsArePredictions && !allowsToBeAutoCorrected);
|
|| (!resultsArePredictions && !allowsToBeAutoCorrected);
|
||||||
|
|
||||||
if (hasAutoCorrection && typedWordFirstOccurrenceWordInfo != null) {
|
if (hasAutoCorrection && typedWordFirstOccurrenceWordInfo != null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue