From af3b56c887b6c0a1bcbb21c50489f2d7ae65f654 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 8 Sep 2011 21:17:24 +0900 Subject: [PATCH] Fix a bug where the wrong suggestion score would matter. Also introduce a few debug prints. Bug: 5240463 Change-Id: Iea2fffa3be9d7bd69da751ece9e67e94e9819ee1 --- .../AndroidSpellCheckerService.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 85c142f1e..ae47ab22b 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -160,6 +160,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService { if (mLength != mSuggestions.size()) { Log.e(TAG, "Suggestion size is not the same as stored mLength"); } + for (int i = mLength - 1; i >= 0; --i) { + Log.i(TAG, "" + mScores[i] + " " + mSuggestions.get(i)); + } } Collections.reverse(mSuggestions); Utils.removeDupes(mSuggestions); @@ -167,11 +170,16 @@ public class AndroidSpellCheckerService extends SpellCheckerService { // into a String[]. gatheredSuggestions = mSuggestions.toArray(EMPTY_STRING_ARRAY); - final int bestScore = mScores[0]; + final int bestScore = mScores[mLength - 1]; final CharSequence bestSuggestion = mSuggestions.get(0); final double normalizedScore = Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore); looksLikeTypo = (normalizedScore > threshold); + if (DBG) { + Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); + Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + threshold + + ") => looksLikeTypo = " + looksLikeTypo); + } } return new Result(gatheredSuggestions, looksLikeTypo); } @@ -305,6 +313,16 @@ public class AndroidSpellCheckerService extends SpellCheckerService { final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, mService.mTypoThreshold); + if (DBG) { + Log.i(TAG, "Spell checking results for " + text + " with suggestion limit " + + suggestionsLimit); + Log.i(TAG, "IsInDict = " + result.mLooksLikeTypo); + Log.i(TAG, "LooksLikeTypo = " + result.mLooksLikeTypo); + for (String suggestion : result.mSuggestions) { + Log.i(TAG, suggestion); + } + } + final int flags = (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0) | (result.mLooksLikeTypo