Make access to the safety net calculation easier

Change-Id: If33897b38af94ae81b05e5ef140a542724b9f34a
main
Jean Chalard 2012-03-09 21:44:40 +09:00
parent 151d5cb532
commit 682c2d53cc
1 changed files with 7 additions and 10 deletions

View File

@ -455,7 +455,7 @@ public class Suggest implements Dictionary.WordCallback {
builder.setTypedWordValid(!allowsToBeAutoCorrected).setHasMinimalSuggestion(
autoCorrectionAvailable);
if (allowsToBeAutoCorrected && builder.size() > 1 && mAutoCorrectionThreshold > 0
&& Suggest.shouldBlockAutoCorrectionBySafetyNet(builder)) {
&& Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord, builder.getWord(1))) {
builder.setShouldBlockAutoCorrectionBySafetyNet();
}
return builder;
@ -608,31 +608,28 @@ public class Suggest implements Dictionary.WordCallback {
// TODO: Resolve the inconsistencies between the native auto correction algorithms and
// this safety net
public static boolean shouldBlockAutoCorrectionBySafetyNet(
final SuggestedWords.Builder suggestedWordsBuilder) {
public static boolean shouldBlockAutoCorrectionBySafetyNet(final String typedWord,
final CharSequence suggestion) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's a bug.
// If user selected aggressive auto correction mode, there is no need to use the safety
// net.
final CharSequence typedWord = suggestedWordsBuilder.getWord(0);
// If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH,
// we should not use net because relatively edit distance can be big.
if (typedWord.length() < Suggest.MINIMUM_SAFETY_NET_CHAR_LENGTH) {
final int typedWordLength = typedWord.length();
if (typedWordLength < Suggest.MINIMUM_SAFETY_NET_CHAR_LENGTH) {
return false;
}
final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1);
final int typedWordLength = typedWord.length();
final int maxEditDistanceOfNativeDictionary =
(typedWordLength < 5 ? 2 : typedWordLength / 2) + 1;
final int distance = BinaryDictionary.editDistance(
typedWord.toString(), suggestionWord.toString());
final int distance = BinaryDictionary.editDistance(typedWord, suggestion.toString());
if (DBG) {
Log.d(TAG, "Autocorrected edit distance = " + distance
+ ", " + maxEditDistanceOfNativeDictionary);
}
if (distance > maxEditDistanceOfNativeDictionary) {
if (DBG) {
Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord);
Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestion);
Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ "Turning off auto-correction.");
}