diff options
author | 2011-02-10 17:31:37 +0900 | |
---|---|---|
committer | 2011-02-10 17:31:37 +0900 | |
commit | a7ea6cad8269c2b621dbf585ed90121b495f6ebc (patch) | |
tree | efe9106dacb45cf2cf4f17d80f870a030436ca53 /java/src/com/android/inputmethod/latin/Utils.java | |
parent | b7b83125544964bf128e07456edfd0170d889dc4 (diff) | |
parent | 03b5579b3b7380f8e12519cca1662317282c6bd9 (diff) | |
download | latinime-a7ea6cad8269c2b621dbf585ed90121b495f6ebc.tar.gz latinime-a7ea6cad8269c2b621dbf585ed90121b495f6ebc.tar.xz latinime-a7ea6cad8269c2b621dbf585ed90121b495f6ebc.zip |
Merge remote branch 'goog/master' into merge
Conflicts:
java/res/xml/method.xml
java/src/com/android/inputmethod/latin/LatinIME.java
java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
Change-Id: I9b62da120dcc08327fde92459ee5c7564a5eb6b8
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Utils.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 160948507..d33d962c0 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -23,6 +23,7 @@ import android.os.HandlerThread; import android.os.Process; import android.text.format.DateUtils; import android.util.Log; +import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import java.io.BufferedReader; @@ -37,6 +38,7 @@ import java.util.Date; public class Utils { private static final String TAG = Utils.class.getSimpleName(); + private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; private static boolean DBG = LatinImeLogger.sDBG; /** @@ -98,12 +100,26 @@ public class Utils { // || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; } + public static String getInputMethodId(InputMethodManager imm, String packageName) { + for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) { + if (imi.getPackageName().equals(packageName)) + return imi.getId(); + } + throw new RuntimeException("Can not find input method id for " + packageName); + } - public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) { + public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions, + Suggest suggest) { // 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; + // If user selected aggressive auto correction mode, there is no need to use the safety + // net. + if (suggest.isAggressiveAutoCorrectionMode()) return false; CharSequence typedWord = suggestions.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() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false; CharSequence candidateWord = suggestions.getWord(1); final int typedWordLength = typedWord.length(); final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; @@ -113,8 +129,11 @@ public class Utils { + ", " + maxEditDistanceOfNativeDictionary); } if (distance > maxEditDistanceOfNativeDictionary) { - Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " - + "Turning off auto-correction."); + if (DBG) { + Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + candidateWord); + Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " + + "Turning off auto-correction."); + } return true; } else { return false; @@ -260,9 +279,12 @@ public class Utils { public static double calcNormalizedScore(CharSequence before, CharSequence after, int score) { final int beforeLength = before.length(); final int afterLength = after.length(); + if (beforeLength == 0 || afterLength == 0) return 0; final int distance = editDistance(before, after); + // If afterLength < beforeLength, the algorithm is suggesting a word by excessive character + // correction. final double maximumScore = MAX_INITIAL_SCORE - * Math.pow(TYPED_LETTER_MULTIPLIER, beforeLength) + * Math.pow(TYPED_LETTER_MULTIPLIER, Math.min(beforeLength, afterLength)) * FULL_WORD_MULTIPLYER; // add a weight based on edit distance. // distance <= max(afterLength, beforeLength) == afterLength, |