diff options
author | 2014-07-10 07:39:56 +0000 | |
---|---|---|
committer | 2014-07-10 07:39:56 +0000 | |
commit | 63285120cfb8e1a1f3c7bdc5c8ebc3eea424585c (patch) | |
tree | 0130b7b616248298f59d68a9669509a5ad4019df /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | |
parent | f2067d6987e17bb26af5eb8548ccb0158a20826b (diff) | |
parent | b7ecb258dc606774ff5792ddbe4f89751d276f89 (diff) | |
download | latinime-63285120cfb8e1a1f3c7bdc5c8ebc3eea424585c.tar.gz latinime-63285120cfb8e1a1f3c7bdc5c8ebc3eea424585c.tar.xz latinime-63285120cfb8e1a1f3c7bdc5c8ebc3eea424585c.zip |
am b7ecb258: Merge "Remove SuggestionsGatherer."
* commit 'b7ecb258dc606774ff5792ddbe4f89751d276f89':
Remove SuggestionsGatherer.
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 { |