From 2aa1dd45c44295e2f7e8ece1b520032d86b9f908 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 13 Oct 2011 14:25:26 +0900 Subject: Fix the safety net Bug: 5453150 Change-Id: I5990feb2622738988bf29843c6bcdb9cbf8bbf33 --- java/src/com/android/inputmethod/latin/Utils.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/Utils.java') diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index de2930460..f6343f1d7 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -167,7 +167,9 @@ public class Utils { throw new RuntimeException("Can not find input method id for " + packageName); } - public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions, + // TODO: Resolve the inconsistencies between the native auto correction algorithms and + // this safety net + public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions, Suggest suggest) { // Safety net for auto correction. // Actually if we hit this safety net, it's actually a bug. @@ -181,7 +183,8 @@ public class Utils { if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false; final CharSequence suggestionWord = suggestions.getWord(1); final int typedWordLength = typedWord.length(); - final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; + final int maxEditDistanceOfNativeDictionary = + (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; final int distance = Utils.editDistance(typedWord, suggestionWord); if (DBG) { Log.d(TAG, "Autocorrected edit distance = " + distance @@ -189,8 +192,8 @@ public class Utils { } if (distance > maxEditDistanceOfNativeDictionary) { if (DBG) { - Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); - Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " + Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); + Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " + "Turning off auto-correction."); } return true; @@ -792,6 +795,7 @@ public class Utils { } public static boolean willAutoCorrect(SuggestedWords suggestions) { - return !suggestions.mTypedWordValid && suggestions.mHasMinimalSuggestion; + return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate + && !suggestions.shouldBlockAutoCorrection(); } } -- cgit v1.2.3-83-g751a