aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Utils.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-01-19 01:05:39 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-01-19 01:05:39 -0800
commit1e6d39104814083011d556376974f241e51a8bed (patch)
tree77d28d5c4c37f246d329c2e2f5ca033e43cafd11 /java/src/com/android/inputmethod/latin/Utils.java
parent53746972d0dda9cbbf3d49cfa71271eaeb5cfe5b (diff)
parentce4b2d2daba8005c2c07a995c8a145ee812f56ff (diff)
downloadlatinime-1e6d39104814083011d556376974f241e51a8bed.tar.gz
latinime-1e6d39104814083011d556376974f241e51a8bed.tar.xz
latinime-1e6d39104814083011d556376974f241e51a8bed.zip
am ce4b2d2d: Merge "Add a safety net for auto-correction." into honeycomb
* commit 'ce4b2d2daba8005c2c07a995c8a145ee812f56ff': Add a safety net for auto-correction.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java25
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';