aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-03-09 21:44:40 +0900
committerJean Chalard <jchalard@google.com>2012-03-09 21:44:40 +0900
commit682c2d53cc5a8ec9d79e4fe4276c6e940c8f251e (patch)
tree1b48689d1796d82f184dcf9ae2ac63d7e02b889b /java/src
parent151d5cb5326f90d4f5856ebb3bb5ce338229ce7f (diff)
downloadlatinime-682c2d53cc5a8ec9d79e4fe4276c6e940c8f251e.tar.gz
latinime-682c2d53cc5a8ec9d79e4fe4276c6e940c8f251e.tar.xz
latinime-682c2d53cc5a8ec9d79e4fe4276c6e940c8f251e.zip
Make access to the safety net calculation easier
Change-Id: If33897b38af94ae81b05e5ef140a542724b9f34a
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java17
1 files changed, 7 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 1112baa71..7d9b50569 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -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.");
}