diff options
author | 2014-07-10 16:23:27 +0900 | |
---|---|---|
committer | 2014-07-10 16:23:27 +0900 | |
commit | 1467fa0c2642e05aef6f588eef0f704b6da3aee2 (patch) | |
tree | f4e580ccb9921a67d9a24ea7f458cd133f6604bb /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | |
parent | 86dee2295dccd9af3c58e946bc8f2b62736c0260 (diff) | |
download | latinime-1467fa0c2642e05aef6f588eef0f704b6da3aee2.tar.gz latinime-1467fa0c2642e05aef6f588eef0f704b6da3aee2.tar.xz latinime-1467fa0c2642e05aef6f588eef0f704b6da3aee2.zip |
Remove SuggestionsGatherer.
Bug: 13689011
Bug: 13630847
Change-Id: I9930d5ce9cbe16489dc69f68b9590d72afe463b5
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | 93 |
1 files changed, 4 insertions, 89 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 26248db75..90398deb2 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -155,6 +155,10 @@ public final class AndroidSpellCheckerService extends SpellCheckerService onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY); } + public float getRecommendedThreshold() { + return mRecommendedThreshold; + } + private static String getKeyboardLayoutNameForScript(final int script) { switch (script) { case ScriptUtils.SCRIPT_LATIN: @@ -214,95 +218,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService EMPTY_STRING_ARRAY); } - public SuggestionsGatherer newSuggestionsGatherer(final String text, int maxLength) { - return new SuggestionsGatherer(text, mRecommendedThreshold, maxLength); - } - - // TODO: remove this class and replace it by storage local to the session. - public static final class SuggestionsGatherer { - public static final class Result { - public final String[] mSuggestions; - public final boolean mHasRecommendedSuggestions; - public Result(final String[] gatheredSuggestions, - final boolean hasRecommendedSuggestions) { - mSuggestions = gatheredSuggestions; - mHasRecommendedSuggestions = hasRecommendedSuggestions; - } - } - - private final ArrayList<String> mSuggestions; - private final ArrayList<Integer> mScores; - private final String mOriginalText; - private final float mRecommendedThreshold; - private final int mMaxLength; - - SuggestionsGatherer(final String originalText, final float recommendedThreshold, - final int maxLength) { - mOriginalText = originalText; - mRecommendedThreshold = recommendedThreshold; - mMaxLength = maxLength; - mSuggestions = new ArrayList<>(); - mScores = new ArrayList<>(); - } - - public void addResults(final SuggestionResults suggestionResults) { - if (suggestionResults == null) { - return; - } - // suggestionResults is sorted. - for (final SuggestedWordInfo suggestedWordInfo : suggestionResults) { - mSuggestions.add(suggestedWordInfo.mWord); - mScores.add(suggestedWordInfo.mScore); - } - } - - public Result getResults(final int capitalizeType, final Locale locale) { - final String[] gatheredSuggestions; - final boolean hasRecommendedSuggestions; - if (mSuggestions.isEmpty()) { - gatheredSuggestions = null; - hasRecommendedSuggestions = false; - } else { - if (DBG) { - for (int i = 0; i < mSuggestions.size(); i++) { - Log.i(TAG, "" + mScores.get(i) + " " + mSuggestions.get(i)); - } - } - StringUtils.removeDupes(mSuggestions); - if (StringUtils.CAPITALIZE_ALL == capitalizeType) { - for (int i = 0; i < mSuggestions.size(); ++i) { - // get(i) returns a CharSequence which is actually a String so .toString() - // should return the same object. - mSuggestions.set(i, mSuggestions.get(i).toString().toUpperCase(locale)); - } - } else if (StringUtils.CAPITALIZE_FIRST == capitalizeType) { - for (int i = 0; i < mSuggestions.size(); ++i) { - // Likewise - mSuggestions.set(i, StringUtils.capitalizeFirstCodePoint( - mSuggestions.get(i).toString(), locale)); - } - } - // This returns a String[], while toArray() returns an Object[] which cannot be cast - // into a String[]. - gatheredSuggestions = mSuggestions.toArray(EMPTY_STRING_ARRAY); - - final int bestScore = mScores.get(0); - final String bestSuggestion = mSuggestions.get(0); - final float normalizedScore = - BinaryDictionaryUtils.calcNormalizedScore( - mOriginalText, bestSuggestion.toString(), bestScore); - hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold); - if (DBG) { - Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); - Log.i(TAG, "Normalized score = " + normalizedScore - + " (threshold " + mRecommendedThreshold - + ") => hasRecommendedSuggestions = " + hasRecommendedSuggestions); - } - } - return new Result(gatheredSuggestions, hasRecommendedSuggestions); - } - } - public boolean isValidWord(final Locale locale, final String word) { mSemaphore.acquireUninterruptibly(); try { |