diff options
author | 2011-01-19 01:02:28 -0800 | |
---|---|---|
committer | 2011-01-19 01:02:28 -0800 | |
commit | ce4b2d2daba8005c2c07a995c8a145ee812f56ff (patch) | |
tree | 77d28d5c4c37f246d329c2e2f5ca033e43cafd11 /java/src/com/android/inputmethod/latin/Utils.java | |
parent | 86f189fd969de7259a0e0fcc1cf868ba667f3e3b (diff) | |
parent | 82411d47ba7e8133ed2390c6920945e139a738ce (diff) | |
download | latinime-ce4b2d2daba8005c2c07a995c8a145ee812f56ff.tar.gz latinime-ce4b2d2daba8005c2c07a995c8a145ee812f56ff.tar.xz latinime-ce4b2d2daba8005c2c07a995c8a145ee812f56ff.zip |
Merge "Add a safety net for auto-correction." into honeycomb
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Utils.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 753e5d64f..d2582b115 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -36,6 +36,8 @@ import java.text.SimpleDateFormat; import java.util.Date; public class Utils { + private static final String TAG = Utils.class.getSimpleName(); + private static boolean DBG = LatinImeLogger.sDBG; /** * Cancel an {@link AsyncTask}. @@ -95,6 +97,29 @@ public class Utils { || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; } + + public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) { + // Safety net for auto correction. + // Actually if we hit this safety net, it's actually a bug. + if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false; + CharSequence typedWord = suggestions.getWord(0); + CharSequence candidateWord = suggestions.getWord(1); + final int typedWordLength = typedWord.length(); + final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; + final int distance = Utils.editDistance(typedWord, candidateWord); + if (DBG) { + Log.d(TAG, "Autocorrected edit distance = " + distance + + ", " + maxEditDistanceOfNativeDictionary); + } + if (distance > maxEditDistanceOfNativeDictionary) { + Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " + + "Turning off auto-correction."); + return true; + } else { + return false; + } + } + /* package */ static class RingCharBuffer { private static RingCharBuffer sRingCharBuffer = new RingCharBuffer(); private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC'; |