Cleanup & optimization
Renaming some variables, and obvious optimizations. Change-Id: Ib716748e9f3d602cf276dcd4e73f3bcfb819585e
This commit is contained in:
parent
f985efe39c
commit
4a08b2f0e4
1 changed files with 24 additions and 28 deletions
|
@ -343,21 +343,22 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (wordComposer.size() > 1) {
|
} else if (wordComposer.size() > 1) {
|
||||||
|
final WordComposer wordComposerForLookup;
|
||||||
|
if (mTrailingSingleQuotesCount > 0) {
|
||||||
|
wordComposerForLookup = new WordComposer(wordComposer);
|
||||||
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
|
wordComposerForLookup.deleteLast();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wordComposerForLookup = wordComposer;
|
||||||
|
}
|
||||||
// At second character typed, search the unigrams (scores being affected by bigrams)
|
// At second character typed, search the unigrams (scores being affected by bigrams)
|
||||||
for (final String key : mUnigramDictionaries.keySet()) {
|
for (final String key : mUnigramDictionaries.keySet()) {
|
||||||
// Skip UserUnigramDictionary and WhitelistDictionary to lookup
|
// Skip UserUnigramDictionary and WhitelistDictionary to lookup
|
||||||
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
||||||
continue;
|
continue;
|
||||||
final Dictionary dictionary = mUnigramDictionaries.get(key);
|
final Dictionary dictionary = mUnigramDictionaries.get(key);
|
||||||
if (mTrailingSingleQuotesCount > 0) {
|
dictionary.getWords(wordComposerForLookup, this, proximityInfo);
|
||||||
final WordComposer tmpWordComposer = new WordComposer(wordComposer);
|
|
||||||
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
|
||||||
tmpWordComposer.deleteLast();
|
|
||||||
}
|
|
||||||
dictionary.getWords(tmpWordComposer, this, proximityInfo);
|
|
||||||
} else {
|
|
||||||
dictionary.getWords(wordComposer, this, proximityInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,41 +392,36 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
mSuggestions.add(0, typedWord);
|
mSuggestions.add(0, typedWord);
|
||||||
StringUtils.removeDupes(mSuggestions);
|
StringUtils.removeDupes(mSuggestions);
|
||||||
|
|
||||||
final ArrayList<SuggestedWords.SuggestedWordInfo> scoreInfoList;
|
final ArrayList<SuggestedWords.SuggestedWordInfo> suggestionsList;
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
// TODO: this doesn't take into account the fact that removing dupes from mSuggestions
|
// TODO: this doesn't take into account the fact that removing dupes from mSuggestions
|
||||||
// may have made mScores[] and mSuggestions out of sync.
|
// may have made mScores[] and mSuggestions out of sync.
|
||||||
final CharSequence autoCorrectionSuggestion = mSuggestions.get(0);
|
final CharSequence autoCorrectionSuggestion = mSuggestions.get(0);
|
||||||
final int autoCorrectionSuggestionScore = mScores[0];
|
|
||||||
double normalizedScore = BinaryDictionary.calcNormalizedScore(
|
double normalizedScore = BinaryDictionary.calcNormalizedScore(
|
||||||
typedWord, autoCorrectionSuggestion.toString(),
|
typedWord, autoCorrectionSuggestion.toString(), mScores[0]);
|
||||||
autoCorrectionSuggestionScore);
|
suggestionsList = new ArrayList<SuggestedWords.SuggestedWordInfo>();
|
||||||
scoreInfoList = new ArrayList<SuggestedWords.SuggestedWordInfo>();
|
suggestionsList.add(new SuggestedWords.SuggestedWordInfo(autoCorrectionSuggestion, "+",
|
||||||
scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(autoCorrectionSuggestion, "+",
|
|
||||||
false));
|
false));
|
||||||
final int suggestionsSize = mSuggestions.size();
|
final int suggestionsSize = mSuggestions.size();
|
||||||
// Note: i here is the index in mScores[], but the index in mSuggestions is one more
|
// Note: i here is the index in mScores[], but the index in mSuggestions is one more
|
||||||
// than i because we added the typed word to mSuggestions without touching mScores.
|
// than i because we added the typed word to mSuggestions without touching mScores.
|
||||||
for (int i = 0; i < mScores.length && i < suggestionsSize - 1; ++i) {
|
for (int i = 0; i < mScores.length && i < suggestionsSize - 1; ++i) {
|
||||||
|
final String scoreInfoString;
|
||||||
if (normalizedScore > 0) {
|
if (normalizedScore > 0) {
|
||||||
final String scoreThreshold = String.format("%d (%4.2f)", mScores[i],
|
scoreInfoString = String.format("%d (%4.2f)", mScores[i], normalizedScore);
|
||||||
normalizedScore);
|
|
||||||
scoreInfoList.add(
|
|
||||||
new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
|
|
||||||
scoreThreshold, false));
|
|
||||||
normalizedScore = 0.0;
|
normalizedScore = 0.0;
|
||||||
} else {
|
} else {
|
||||||
final String score = Integer.toString(mScores[i]);
|
scoreInfoString = Integer.toString(mScores[i]);
|
||||||
scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
|
|
||||||
score, false));
|
|
||||||
}
|
}
|
||||||
|
suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i + 1),
|
||||||
|
scoreInfoString, false));
|
||||||
}
|
}
|
||||||
for (int i = mScores.length; i < suggestionsSize; ++i) {
|
for (int i = mScores.length; i < suggestionsSize; ++i) {
|
||||||
scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i),
|
suggestionsList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i),
|
||||||
"--", false));
|
"--", false));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scoreInfoList = SuggestedWords.getFromCharSequenceList(mSuggestions);
|
suggestionsList = SuggestedWords.getFromCharSequenceList(mSuggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean autoCorrectionAvailable = hasAutoCorrection;
|
boolean autoCorrectionAvailable = hasAutoCorrection;
|
||||||
|
@ -436,14 +432,14 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
// Don't auto-correct words with multiple capital letter
|
// Don't auto-correct words with multiple capital letter
|
||||||
autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
|
autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
|
||||||
final boolean shouldBlockAutoCorrectionBySatefyNet;
|
final boolean shouldBlockAutoCorrectionBySatefyNet;
|
||||||
if (allowsToBeAutoCorrected && scoreInfoList.size() > 1 && mAutoCorrectionThreshold > 0
|
if (allowsToBeAutoCorrected && suggestionsList.size() > 1 && mAutoCorrectionThreshold > 0
|
||||||
&& Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord,
|
&& Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord,
|
||||||
scoreInfoList.get(1).mWord)) {
|
suggestionsList.get(1).mWord)) {
|
||||||
shouldBlockAutoCorrectionBySatefyNet = true;
|
shouldBlockAutoCorrectionBySatefyNet = true;
|
||||||
} else {
|
} else {
|
||||||
shouldBlockAutoCorrectionBySatefyNet = false;
|
shouldBlockAutoCorrectionBySatefyNet = false;
|
||||||
}
|
}
|
||||||
return new SuggestedWords(scoreInfoList,
|
return new SuggestedWords(suggestionsList,
|
||||||
!allowsToBeAutoCorrected /* typedWordValid */,
|
!allowsToBeAutoCorrected /* typedWordValid */,
|
||||||
autoCorrectionAvailable & !shouldBlockAutoCorrectionBySatefyNet
|
autoCorrectionAvailable & !shouldBlockAutoCorrectionBySatefyNet
|
||||||
/* hasAutoCorrectionCandidate */,
|
/* hasAutoCorrectionCandidate */,
|
||||||
|
|
Loading…
Reference in a new issue