Merge "Move some arguments to final members."
This commit is contained in:
commit
2f1fdf2889
1 changed files with 15 additions and 11 deletions
|
@ -95,6 +95,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
private final int DEFAULT_SUGGESTION_LENGTH = 16;
|
private final int DEFAULT_SUGGESTION_LENGTH = 16;
|
||||||
private final ArrayList<CharSequence> mSuggestions;
|
private final ArrayList<CharSequence> mSuggestions;
|
||||||
private final int[] mScores;
|
private final int[] mScores;
|
||||||
|
private final String mOriginalText;
|
||||||
|
private final double mThreshold;
|
||||||
private final int mMaxLength;
|
private final int mMaxLength;
|
||||||
private int mLength = 0;
|
private int mLength = 0;
|
||||||
|
|
||||||
|
@ -103,7 +105,10 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
private String mBestSuggestion = null;
|
private String mBestSuggestion = null;
|
||||||
private int mBestScore = Integer.MIN_VALUE; // As small as possible
|
private int mBestScore = Integer.MIN_VALUE; // As small as possible
|
||||||
|
|
||||||
SuggestionsGatherer(final int maxLength) {
|
SuggestionsGatherer(final String originalText, final double threshold,
|
||||||
|
final int maxLength) {
|
||||||
|
mOriginalText = originalText;
|
||||||
|
mThreshold = threshold;
|
||||||
mMaxLength = maxLength;
|
mMaxLength = maxLength;
|
||||||
mSuggestions = new ArrayList<CharSequence>(maxLength + 1);
|
mSuggestions = new ArrayList<CharSequence>(maxLength + 1);
|
||||||
mScores = new int[mMaxLength];
|
mScores = new int[mMaxLength];
|
||||||
|
@ -146,8 +151,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result getResults(final CharSequence originalText, final double threshold,
|
public Result getResults(final int capitalizeType, final Locale locale) {
|
||||||
final int capitalizeType, final Locale locale) {
|
|
||||||
final String[] gatheredSuggestions;
|
final String[] gatheredSuggestions;
|
||||||
final boolean hasLikelySuggestions;
|
final boolean hasLikelySuggestions;
|
||||||
if (0 == mLength) {
|
if (0 == mLength) {
|
||||||
|
@ -160,8 +164,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
} else {
|
} else {
|
||||||
gatheredSuggestions = EMPTY_STRING_ARRAY;
|
gatheredSuggestions = EMPTY_STRING_ARRAY;
|
||||||
final double normalizedScore =
|
final double normalizedScore =
|
||||||
Utils.calcNormalizedScore(originalText, mBestSuggestion, mBestScore);
|
Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore);
|
||||||
hasLikelySuggestions = (normalizedScore > threshold);
|
hasLikelySuggestions = (normalizedScore > mThreshold);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
|
@ -194,11 +198,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
final int bestScore = mScores[mLength - 1];
|
final int bestScore = mScores[mLength - 1];
|
||||||
final CharSequence bestSuggestion = mSuggestions.get(0);
|
final CharSequence bestSuggestion = mSuggestions.get(0);
|
||||||
final double normalizedScore =
|
final double normalizedScore =
|
||||||
Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore);
|
Utils.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore);
|
||||||
hasLikelySuggestions = (normalizedScore > threshold);
|
hasLikelySuggestions = (normalizedScore > mThreshold);
|
||||||
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 + " (threshold " + threshold
|
Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + mThreshold
|
||||||
+ ") => hasLikelySuggestions = " + hasLikelySuggestions);
|
+ ") => hasLikelySuggestions = " + hasLikelySuggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +355,7 @@ 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 =
|
final SuggestionsGatherer suggestionsGatherer =
|
||||||
new SuggestionsGatherer(suggestionsLimit);
|
new SuggestionsGatherer(text, mService.mTypoThreshold, 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) {
|
||||||
|
@ -392,8 +396,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text,
|
final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(
|
||||||
mService.mTypoThreshold, capitalizeType, mLocale);
|
capitalizeType, mLocale);
|
||||||
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.i(TAG, "Spell checking results for " + text + " with suggestion limit "
|
Log.i(TAG, "Spell checking results for " + text + " with suggestion limit "
|
||||||
|
|
Loading…
Reference in a new issue