am 09f7e656: Merge "Fill in the HAS_RECOMMENDED_SUGGESTIONS flag."

* commit '09f7e656df3bd1d8b8ed378267881ab7925c15fa':
  Fill in the HAS_RECOMMENDED_SUGGESTIONS flag.
main
Jean Chalard 2011-11-11 15:58:55 -08:00 committed by Android Git Automerger
commit e55f79d57e
2 changed files with 27 additions and 23 deletions

View File

@ -80,8 +80,8 @@
will be subject to auto-correction. --> will be subject to auto-correction. -->
<item>0</item> <item>0</item>
</string-array> </string-array>
<!-- Threshold of the normalized score of the best suggestion for the spell checker to declare a word to be "likely" --> <!-- Threshold of the normalized score of the best suggestion for the spell checker to declare a word to be "recommended" -->
<string name="spellchecker_likely_threshold_value" translatable="false">0.11</string> <string name="spellchecker_recommended_threshold_value" translatable="false">0.11</string>
<!-- Threshold of the normalized score of any dictionary lookup to be offered as a suggestion by the spell checker --> <!-- Threshold of the normalized score of any dictionary lookup to be offered as a suggestion by the spell checker -->
<string name="spellchecker_suggestion_threshold_value" translatable="false">0.03</string> <string name="spellchecker_suggestion_threshold_value" translatable="false">0.03</string>
<!-- Screen metrics for logging. <!-- Screen metrics for logging.

View File

@ -82,15 +82,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// The threshold for a candidate to be offered as a suggestion. // The threshold for a candidate to be offered as a suggestion.
private double mSuggestionThreshold; private double mSuggestionThreshold;
// The threshold for a suggestion to be considered "likely". // The threshold for a suggestion to be considered "recommended".
private double mLikelyThreshold; private double mRecommendedThreshold;
@Override public void onCreate() { @Override public void onCreate() {
super.onCreate(); super.onCreate();
mSuggestionThreshold = mSuggestionThreshold =
Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value)); Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value));
mLikelyThreshold = mRecommendedThreshold =
Double.parseDouble(getString(R.string.spellchecker_likely_threshold_value)); Double.parseDouble(getString(R.string.spellchecker_recommended_threshold_value));
} }
@Override @Override
@ -110,10 +110,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private static class SuggestionsGatherer implements WordCallback { private static class SuggestionsGatherer implements WordCallback {
public static class Result { public static class Result {
public final String[] mSuggestions; public final String[] mSuggestions;
public final boolean mHasLikelySuggestions; public final boolean mHasRecommendedSuggestions;
public Result(final String[] gatheredSuggestions, final boolean hasLikelySuggestions) { public Result(final String[] gatheredSuggestions,
final boolean hasRecommendedSuggestions) {
mSuggestions = gatheredSuggestions; mSuggestions = gatheredSuggestions;
mHasLikelySuggestions = hasLikelySuggestions; mHasRecommendedSuggestions = hasRecommendedSuggestions;
} }
} }
@ -121,7 +122,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private final int[] mScores; private final int[] mScores;
private final String mOriginalText; private final String mOriginalText;
private final double mSuggestionThreshold; private final double mSuggestionThreshold;
private final double mLikelyThreshold; private final double mRecommendedThreshold;
private final int mMaxLength; private final int mMaxLength;
private int mLength = 0; private int mLength = 0;
@ -131,10 +132,10 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private int mBestScore = Integer.MIN_VALUE; // As small as possible private int mBestScore = Integer.MIN_VALUE; // As small as possible
SuggestionsGatherer(final String originalText, final double suggestionThreshold, SuggestionsGatherer(final String originalText, final double suggestionThreshold,
final double likelyThreshold, final int maxLength) { final double recommendedThreshold, final int maxLength) {
mOriginalText = originalText; mOriginalText = originalText;
mSuggestionThreshold = suggestionThreshold; mSuggestionThreshold = suggestionThreshold;
mLikelyThreshold = likelyThreshold; mRecommendedThreshold = recommendedThreshold;
mMaxLength = maxLength; mMaxLength = maxLength;
mSuggestions = new ArrayList<CharSequence>(maxLength + 1); mSuggestions = new ArrayList<CharSequence>(maxLength + 1);
mScores = new int[mMaxLength]; mScores = new int[mMaxLength];
@ -198,19 +199,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
public Result getResults(final int capitalizeType, final Locale locale) { public Result getResults(final int capitalizeType, final Locale locale) {
final String[] gatheredSuggestions; final String[] gatheredSuggestions;
final boolean hasLikelySuggestions; final boolean hasRecommendedSuggestions;
if (0 == mLength) { if (0 == mLength) {
// Either we found no suggestions, or we found some BUT the max length was 0. // Either we found no suggestions, or we found some BUT the max length was 0.
// If we found some mBestSuggestion will not be null. If it is null, then // If we found some mBestSuggestion will not be null. If it is null, then
// we found none, regardless of the max length. // we found none, regardless of the max length.
if (null == mBestSuggestion) { if (null == mBestSuggestion) {
gatheredSuggestions = null; gatheredSuggestions = null;
hasLikelySuggestions = false; hasRecommendedSuggestions = false;
} else { } else {
gatheredSuggestions = EMPTY_STRING_ARRAY; gatheredSuggestions = EMPTY_STRING_ARRAY;
final double normalizedScore = final double normalizedScore =
Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore); Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore);
hasLikelySuggestions = (normalizedScore > mLikelyThreshold); hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);
} }
} else { } else {
if (DBG) { if (DBG) {
@ -244,15 +245,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final CharSequence bestSuggestion = mSuggestions.get(0); final CharSequence bestSuggestion = mSuggestions.get(0);
final double normalizedScore = final double normalizedScore =
Utils.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore); Utils.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore);
hasLikelySuggestions = (normalizedScore > mLikelyThreshold); hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);
if (DBG) { if (DBG) {
Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore);
Log.i(TAG, "Normalized score = " + normalizedScore Log.i(TAG, "Normalized score = " + normalizedScore
+ " (threshold " + mLikelyThreshold + " (threshold " + mRecommendedThreshold
+ ") => hasLikelySuggestions = " + hasLikelySuggestions); + ") => hasRecommendedSuggestions = " + hasRecommendedSuggestions);
} }
} }
return new Result(gatheredSuggestions, hasLikelySuggestions); return new Result(gatheredSuggestions, hasRecommendedSuggestions);
} }
} }
@ -426,7 +427,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// TODO: Don't gather suggestions if the limit is <= 0 unless necessary // TODO: Don't gather suggestions if the limit is <= 0 unless necessary
final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(text, final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(text,
mService.mSuggestionThreshold, mService.mLikelyThreshold, suggestionsLimit); mService.mSuggestionThreshold, mService.mRecommendedThreshold,
suggestionsLimit);
final WordComposer composer = new WordComposer(); final WordComposer composer = new WordComposer();
final int length = text.length(); final int length = text.length();
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
@ -475,7 +477,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
+ suggestionsLimit); + suggestionsLimit);
Log.i(TAG, "IsInDict = " + isInDict); Log.i(TAG, "IsInDict = " + isInDict);
Log.i(TAG, "LooksLikeTypo = " + (!isInDict)); Log.i(TAG, "LooksLikeTypo = " + (!isInDict));
Log.i(TAG, "HasLikelySuggestions = " + result.mHasLikelySuggestions); Log.i(TAG, "HasRecommendedSuggestions = " + result.mHasRecommendedSuggestions);
if (null != result.mSuggestions) { if (null != result.mSuggestions) {
for (String suggestion : result.mSuggestions) { for (String suggestion : result.mSuggestions) {
Log.i(TAG, suggestion); Log.i(TAG, suggestion);
@ -483,10 +485,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
} }
} }
// TODO: actually use result.mHasLikelySuggestions
final int flags = final int flags =
(isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY
: SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO); : SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO)
| (result.mHasRecommendedSuggestions
? SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS
: 0);
return new SuggestionsInfo(flags, result.mSuggestions); return new SuggestionsInfo(flags, result.mSuggestions);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// Don't kill the keyboard if there is a bug in the spell checker // Don't kill the keyboard if there is a bug in the spell checker