2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2011-01-07 06:01:51 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-01-07 06:01:51 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-01-07 06:01:51 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
2011-08-04 03:08:22 +00:00
|
|
|
import com.android.inputmethod.keyboard.ProximityInfo;
|
2012-03-14 09:33:57 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
2014-07-17 01:41:46 +00:00
|
|
|
import com.android.inputmethod.latin.define.DebugFlags;
|
2014-07-08 07:36:06 +00:00
|
|
|
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
|
2013-07-18 13:59:26 +00:00
|
|
|
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
2014-03-05 09:19:34 +00:00
|
|
|
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.StringUtils;
|
2014-03-25 06:35:20 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SuggestionResults;
|
2011-08-04 03:08:22 +00:00
|
|
|
|
2010-11-29 08:57:48 +00:00
|
|
|
import java.util.ArrayList;
|
2011-03-14 18:46:15 +00:00
|
|
|
import java.util.Locale;
|
2010-11-29 08:57:48 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
2011-01-07 06:01:51 +00:00
|
|
|
* This class loads a dictionary and provides a list of suggestions for a given sequence of
|
2009-03-13 22:11:42 +00:00
|
|
|
* characters. This includes corrections and completions.
|
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class Suggest {
|
2011-01-18 08:22:01 +00:00
|
|
|
public static final String TAG = Suggest.class.getSimpleName();
|
2010-12-08 07:04:16 +00:00
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
// Session id for
|
2012-10-03 06:19:43 +00:00
|
|
|
// {@link #getSuggestedWords(WordComposer,String,ProximityInfo,boolean,int)}.
|
2013-09-12 03:08:22 +00:00
|
|
|
// We are sharing the same ID between typing and gesture to save RAM footprint.
|
2014-08-14 03:48:50 +00:00
|
|
|
public static final int SESSION_ID_TYPING = 0;
|
|
|
|
public static final int SESSION_ID_GESTURE = 0;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2013-04-14 12:53:16 +00:00
|
|
|
// Close to -2**31
|
|
|
|
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
|
|
|
|
|
2014-07-17 01:41:46 +00:00
|
|
|
private static final boolean DBG = DebugFlags.DEBUG_ENABLED;
|
2014-05-23 00:30:55 +00:00
|
|
|
private final DictionaryFacilitator mDictionaryFacilitator;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2012-05-16 11:42:12 +00:00
|
|
|
private float mAutoCorrectionThreshold;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2014-05-23 00:30:55 +00:00
|
|
|
public Suggest(final DictionaryFacilitator dictionaryFacilitator) {
|
|
|
|
mDictionaryFacilitator = dictionaryFacilitator;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
public Locale getLocale() {
|
|
|
|
return mDictionaryFacilitator.getLocale();
|
2013-08-22 07:43:19 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
public void setAutoCorrectionThreshold(final float threshold) {
|
2010-12-11 08:06:24 +00:00
|
|
|
mAutoCorrectionThreshold = threshold;
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 06:15:49 +00:00
|
|
|
public interface OnGetSuggestedWordsCallback {
|
|
|
|
public void onGetSuggestedWords(final SuggestedWords suggestedWords);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void getSuggestedWords(final WordComposer wordComposer,
|
2014-05-19 04:55:40 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
2014-07-08 07:36:06 +00:00
|
|
|
final SettingsValuesForSuggestion settingsValuesForSuggestion,
|
2014-08-14 03:48:50 +00:00
|
|
|
final boolean isCorrectionEnabled, final int inputStyle, final int sequenceNumber,
|
2013-08-29 06:15:49 +00:00
|
|
|
final OnGetSuggestedWordsCallback callback) {
|
2012-07-10 01:46:13 +00:00
|
|
|
if (wordComposer.isBatchMode()) {
|
2014-05-19 04:55:40 +00:00
|
|
|
getSuggestedWordsForBatchInput(wordComposer, prevWordsInfo, proximityInfo,
|
2014-08-14 03:48:50 +00:00
|
|
|
settingsValuesForSuggestion, inputStyle, sequenceNumber, callback);
|
2012-07-10 01:46:13 +00:00
|
|
|
} else {
|
2014-08-14 03:48:50 +00:00
|
|
|
getSuggestedWordsForNonBatchInput(wordComposer, prevWordsInfo, proximityInfo,
|
|
|
|
settingsValuesForSuggestion, inputStyle, isCorrectionEnabled,
|
|
|
|
sequenceNumber, callback);
|
2012-07-10 01:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 07:43:32 +00:00
|
|
|
private static ArrayList<SuggestedWordInfo> getTransformedSuggestedWordInfoList(
|
|
|
|
final WordComposer wordComposer, final SuggestionResults results,
|
|
|
|
final int trailingSingleQuotesCount) {
|
|
|
|
final boolean shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase()
|
|
|
|
&& !wordComposer.isResumed();
|
|
|
|
final boolean isOnlyFirstCharCapitalized =
|
|
|
|
wordComposer.isOrWillBeOnlyFirstCharCapitalized();
|
|
|
|
|
|
|
|
final ArrayList<SuggestedWordInfo> suggestionsContainer = new ArrayList<>(results);
|
|
|
|
final int suggestionsCount = suggestionsContainer.size();
|
|
|
|
if (isOnlyFirstCharCapitalized || shouldMakeSuggestionsAllUpperCase
|
|
|
|
|| 0 != trailingSingleQuotesCount) {
|
|
|
|
for (int i = 0; i < suggestionsCount; ++i) {
|
|
|
|
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
|
|
|
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
|
|
|
|
wordInfo, results.mLocale, shouldMakeSuggestionsAllUpperCase,
|
|
|
|
isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
|
|
|
|
suggestionsContainer.set(i, transformedWordInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return suggestionsContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getWhitelistedWordOrNull(final ArrayList<SuggestedWordInfo> suggestions) {
|
|
|
|
if (suggestions.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final SuggestedWordInfo firstSuggestedWordInfo = suggestions.get(0);
|
|
|
|
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return firstSuggestedWordInfo.mWord;
|
|
|
|
}
|
|
|
|
|
2014-08-14 03:48:50 +00:00
|
|
|
// Retrieves suggestions for non-batch input (typing, recorrection, predictions...)
|
2013-08-29 06:15:49 +00:00
|
|
|
// and calls the callback function with the suggestions.
|
2014-08-14 03:48:50 +00:00
|
|
|
private void getSuggestedWordsForNonBatchInput(final WordComposer wordComposer,
|
2014-05-19 04:55:40 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
2014-08-26 09:54:08 +00:00
|
|
|
final SettingsValuesForSuggestion settingsValuesForSuggestion,
|
|
|
|
final int inputStyleIfNotPrediction, final boolean isCorrectionEnabled,
|
|
|
|
final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
|
2011-11-18 11:03:38 +00:00
|
|
|
final String typedWord = wordComposer.getTypedWord();
|
2014-05-16 06:32:12 +00:00
|
|
|
final int trailingSingleQuotesCount = StringUtils.getTrailingSingleQuotesCount(typedWord);
|
2012-06-27 10:53:20 +00:00
|
|
|
final String consideredWord = trailingSingleQuotesCount > 0
|
|
|
|
? typedWord.substring(0, typedWord.length() - trailingSingleQuotesCount)
|
2011-11-29 05:15:41 +00:00
|
|
|
: typedWord;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
2014-07-08 07:36:06 +00:00
|
|
|
wordComposer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion,
|
2014-08-14 03:48:50 +00:00
|
|
|
SESSION_ID_TYPING);
|
2014-06-19 07:15:25 +00:00
|
|
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
2014-06-19 07:43:32 +00:00
|
|
|
getTransformedSuggestedWordInfoList(wordComposer, suggestionResults,
|
|
|
|
trailingSingleQuotesCount);
|
2014-06-19 07:27:04 +00:00
|
|
|
final boolean didRemoveTypedWord =
|
2014-06-19 07:43:32 +00:00
|
|
|
SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer);
|
2014-06-19 07:15:25 +00:00
|
|
|
|
2014-06-19 07:43:32 +00:00
|
|
|
final String whitelistedWord = getWhitelistedWordOrNull(suggestionsContainer);
|
|
|
|
final boolean resultsArePredictions = !wordComposer.isComposingWord();
|
2012-08-10 05:50:30 +00:00
|
|
|
|
2014-06-19 07:27:04 +00:00
|
|
|
// We allow auto-correction if we have a whitelisted word, or if the word had more than
|
|
|
|
// one char and was not suggested.
|
|
|
|
final boolean allowsToBeAutoCorrected = (null != whitelistedWord)
|
|
|
|
|| (consideredWord.length() > 1 && !didRemoveTypedWord);
|
2012-08-10 05:31:12 +00:00
|
|
|
|
2012-03-09 08:53:20 +00:00
|
|
|
final boolean hasAutoCorrection;
|
2012-07-09 04:06:12 +00:00
|
|
|
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
|
|
|
|
// any attempt to do auto-correction is already shielded with a test for this flag; at the
|
|
|
|
// same time, it feels wrong that the SuggestedWord object includes information about
|
|
|
|
// the current settings. It may also be useful to know, when the setting is off, whether
|
|
|
|
// the word *would* have been auto-corrected.
|
2014-06-19 07:43:32 +00:00
|
|
|
if (!isCorrectionEnabled || !allowsToBeAutoCorrected || resultsArePredictions
|
|
|
|
|| suggestionResults.isEmpty() || wordComposer.hasDigits()
|
2013-12-26 11:28:37 +00:00
|
|
|
|| wordComposer.isMostlyCaps() || wordComposer.isResumed()
|
2014-03-25 06:35:20 +00:00
|
|
|
|| !mDictionaryFacilitator.hasInitializedMainDictionary()
|
2014-06-19 07:43:32 +00:00
|
|
|
|| suggestionResults.first().isKindOf(SuggestedWordInfo.KIND_SHORTCUT)) {
|
2012-06-28 11:10:19 +00:00
|
|
|
// If we don't have a main dictionary, we never want to auto-correct. The reason for
|
|
|
|
// this is, the user may have a contact whose name happens to match a valid word in
|
|
|
|
// their language, and it will unexpectedly auto-correct. For example, if the user
|
|
|
|
// types in English with no dictionary and has a "Will" in their contact list, "will"
|
|
|
|
// would always auto-correct to "Will" which is unwanted. Hence, no main dict => no
|
|
|
|
// auto-correct.
|
2013-10-07 08:10:23 +00:00
|
|
|
// Also, shortcuts should never auto-correct unless they are whitelist entries.
|
|
|
|
// TODO: we may want to have shortcut-only entries auto-correct in the future.
|
2012-06-28 08:07:30 +00:00
|
|
|
hasAutoCorrection = false;
|
2012-03-09 03:51:15 +00:00
|
|
|
} else {
|
2013-07-18 13:59:26 +00:00
|
|
|
hasAutoCorrection = AutoCorrectionUtils.suggestionExceedsAutoCorrectionThreshold(
|
2014-06-19 07:43:32 +00:00
|
|
|
suggestionResults.first(), consideredWord, mAutoCorrectionThreshold);
|
2012-03-09 03:51:15 +00:00
|
|
|
}
|
2011-03-02 06:40:08 +00:00
|
|
|
|
2012-06-28 07:22:19 +00:00
|
|
|
if (!TextUtils.isEmpty(typedWord)) {
|
2012-06-26 10:20:20 +00:00
|
|
|
suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
|
2012-06-27 09:17:28 +00:00
|
|
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED,
|
2013-08-20 07:11:03 +00:00
|
|
|
Dictionary.DICTIONARY_USER_TYPED,
|
2013-08-20 09:00:21 +00:00
|
|
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
|
|
|
|
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
|
2012-06-26 06:17:51 +00:00
|
|
|
}
|
2011-03-02 06:40:08 +00:00
|
|
|
|
2012-03-14 09:33:57 +00:00
|
|
|
final ArrayList<SuggestedWordInfo> suggestionsList;
|
2012-06-26 10:20:20 +00:00
|
|
|
if (DBG && !suggestionsContainer.isEmpty()) {
|
|
|
|
suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, suggestionsContainer);
|
2012-03-09 10:42:20 +00:00
|
|
|
} else {
|
2012-06-26 10:20:20 +00:00
|
|
|
suggestionsList = suggestionsContainer;
|
2011-01-31 05:49:33 +00:00
|
|
|
}
|
2012-03-09 10:42:20 +00:00
|
|
|
|
2014-08-26 09:54:08 +00:00
|
|
|
final int inputStyle = resultsArePredictions ? SuggestedWords.INPUT_STYLE_PREDICTION :
|
|
|
|
inputStyleIfNotPrediction;
|
2014-06-19 06:07:17 +00:00
|
|
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
|
|
|
|
suggestionResults.mRawSuggestions,
|
2012-06-28 08:39:21 +00:00
|
|
|
// TODO: this first argument is lying. If this is a whitelisted word which is an
|
|
|
|
// actual word, it says typedWordValid = false, which looks wrong. We should either
|
|
|
|
// rename the attribute or change the value.
|
2014-06-19 07:43:32 +00:00
|
|
|
!resultsArePredictions && !allowsToBeAutoCorrected /* typedWordValid */,
|
2014-06-19 06:07:17 +00:00
|
|
|
hasAutoCorrection /* willAutoCorrect */,
|
2014-08-26 09:54:08 +00:00
|
|
|
false /* isObsoleteSuggestions */, inputStyle, sequenceNumber));
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 06:15:49 +00:00
|
|
|
// Retrieves suggestions for the batch input
|
|
|
|
// and calls the callback function with the suggestions.
|
|
|
|
private void getSuggestedWordsForBatchInput(final WordComposer wordComposer,
|
2014-05-19 04:55:40 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
2014-07-08 07:36:06 +00:00
|
|
|
final SettingsValuesForSuggestion settingsValuesForSuggestion,
|
2014-08-14 03:48:50 +00:00
|
|
|
final int inputStyle, final int sequenceNumber,
|
2013-10-22 01:51:11 +00:00
|
|
|
final OnGetSuggestedWordsCallback callback) {
|
2014-03-25 06:35:20 +00:00
|
|
|
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
2014-08-14 03:48:50 +00:00
|
|
|
wordComposer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion,
|
|
|
|
SESSION_ID_GESTURE);
|
2012-07-10 01:46:13 +00:00
|
|
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
2014-05-23 11:18:17 +00:00
|
|
|
new ArrayList<>(suggestionResults);
|
2012-06-12 10:40:37 +00:00
|
|
|
final int suggestionsCount = suggestionsContainer.size();
|
2012-08-21 10:57:21 +00:00
|
|
|
final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock();
|
|
|
|
final boolean isAllUpperCase = wordComposer.isAllUpperCase();
|
2012-06-12 10:40:37 +00:00
|
|
|
if (isFirstCharCapitalized || isAllUpperCase) {
|
|
|
|
for (int i = 0; i < suggestionsCount; ++i) {
|
|
|
|
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
|
|
|
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
|
2014-03-25 06:35:20 +00:00
|
|
|
wordInfo, suggestionResults.mLocale, isAllUpperCase, isFirstCharCapitalized,
|
2012-06-12 10:40:37 +00:00
|
|
|
0 /* trailingSingleQuotesCount */);
|
|
|
|
suggestionsContainer.set(i, transformedWordInfo);
|
|
|
|
}
|
|
|
|
}
|
2012-07-10 01:46:13 +00:00
|
|
|
|
2013-04-12 11:45:18 +00:00
|
|
|
if (suggestionsContainer.size() > 1 && TextUtils.equals(suggestionsContainer.get(0).mWord,
|
|
|
|
wordComposer.getRejectedBatchModeSuggestion())) {
|
|
|
|
final SuggestedWordInfo rejected = suggestionsContainer.remove(0);
|
|
|
|
suggestionsContainer.add(1, rejected);
|
|
|
|
}
|
2014-06-19 07:12:34 +00:00
|
|
|
SuggestedWordInfo.removeDups(null /* typedWord */, suggestionsContainer);
|
2013-04-14 12:53:16 +00:00
|
|
|
|
|
|
|
// For some reason some suggestions with MIN_VALUE are making their way here.
|
|
|
|
// TODO: Find a more robust way to detect distractors.
|
|
|
|
for (int i = suggestionsContainer.size() - 1; i >= 0; --i) {
|
|
|
|
if (suggestionsContainer.get(i).mScore < SUPPRESS_SUGGEST_THRESHOLD) {
|
|
|
|
suggestionsContainer.remove(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 10:40:37 +00:00
|
|
|
// In the batch input mode, the most relevant suggested word should act as a "typed word"
|
|
|
|
// (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
|
2014-06-19 06:07:17 +00:00
|
|
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
|
|
|
|
suggestionResults.mRawSuggestions,
|
2012-07-10 01:46:13 +00:00
|
|
|
true /* typedWordValid */,
|
2012-06-12 10:40:37 +00:00
|
|
|
false /* willAutoCorrect */,
|
2012-07-10 01:46:13 +00:00
|
|
|
false /* isObsoleteSuggestions */,
|
2014-08-14 03:48:50 +00:00
|
|
|
inputStyle, sequenceNumber));
|
2012-07-10 01:46:13 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 09:43:32 +00:00
|
|
|
private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo(
|
2012-04-02 07:33:24 +00:00
|
|
|
final String typedWord, final ArrayList<SuggestedWordInfo> suggestions) {
|
|
|
|
final SuggestedWordInfo typedWordInfo = suggestions.get(0);
|
|
|
|
typedWordInfo.setDebugString("+");
|
2012-03-14 09:43:32 +00:00
|
|
|
final int suggestionsSize = suggestions.size();
|
2014-05-23 11:18:17 +00:00
|
|
|
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<>(suggestionsSize);
|
2012-04-02 07:33:24 +00:00
|
|
|
suggestionsList.add(typedWordInfo);
|
2012-03-14 09:43:32 +00:00
|
|
|
// 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.
|
2012-04-02 07:33:24 +00:00
|
|
|
for (int i = 0; i < suggestionsSize - 1; ++i) {
|
|
|
|
final SuggestedWordInfo cur = suggestions.get(i + 1);
|
2014-03-05 09:19:34 +00:00
|
|
|
final float normalizedScore = BinaryDictionaryUtils.calcNormalizedScore(
|
2012-05-15 08:43:31 +00:00
|
|
|
typedWord, cur.toString(), cur.mScore);
|
2012-03-14 09:43:32 +00:00
|
|
|
final String scoreInfoString;
|
|
|
|
if (normalizedScore > 0) {
|
2013-05-24 19:06:02 +00:00
|
|
|
scoreInfoString = String.format(
|
2013-12-13 08:09:16 +00:00
|
|
|
Locale.ROOT, "%d (%4.2f), %s", cur.mScore, normalizedScore,
|
|
|
|
cur.mSourceDict.mDictType);
|
2012-03-14 09:43:32 +00:00
|
|
|
} else {
|
2012-04-02 07:33:24 +00:00
|
|
|
scoreInfoString = Integer.toString(cur.mScore);
|
2012-03-14 09:43:32 +00:00
|
|
|
}
|
2012-04-02 07:33:24 +00:00
|
|
|
cur.setDebugString(scoreInfoString);
|
|
|
|
suggestionsList.add(cur);
|
2012-03-14 09:43:32 +00:00
|
|
|
}
|
|
|
|
return suggestionsList;
|
|
|
|
}
|
|
|
|
|
2013-09-17 10:43:22 +00:00
|
|
|
/* package for test */ static SuggestedWordInfo getTransformedSuggestedWordInfo(
|
2012-06-26 10:46:43 +00:00
|
|
|
final SuggestedWordInfo wordInfo, final Locale locale, final boolean isAllUpperCase,
|
2014-06-09 10:31:41 +00:00
|
|
|
final boolean isOnlyFirstCharCapitalized, final int trailingSingleQuotesCount) {
|
2012-06-28 09:45:16 +00:00
|
|
|
final StringBuilder sb = new StringBuilder(wordInfo.mWord.length());
|
2012-06-26 10:46:43 +00:00
|
|
|
if (isAllUpperCase) {
|
2012-10-03 06:19:43 +00:00
|
|
|
sb.append(wordInfo.mWord.toUpperCase(locale));
|
2014-06-09 10:31:41 +00:00
|
|
|
} else if (isOnlyFirstCharCapitalized) {
|
2013-04-10 08:13:26 +00:00
|
|
|
sb.append(StringUtils.capitalizeFirstCodePoint(wordInfo.mWord, locale));
|
2012-06-26 10:46:43 +00:00
|
|
|
} else {
|
|
|
|
sb.append(wordInfo.mWord);
|
|
|
|
}
|
2013-09-17 10:43:22 +00:00
|
|
|
// Appending quotes is here to help people quote words. However, it's not helpful
|
|
|
|
// when they type words with quotes toward the end like "it's" or "didn't", where
|
|
|
|
// it's more likely the user missed the last character (or didn't type it yet).
|
|
|
|
final int quotesToAppend = trailingSingleQuotesCount
|
|
|
|
- (-1 == wordInfo.mWord.indexOf(Constants.CODE_SINGLE_QUOTE) ? 0 : 1);
|
|
|
|
for (int i = quotesToAppend - 1; i >= 0; --i) {
|
2012-10-29 05:46:34 +00:00
|
|
|
sb.appendCodePoint(Constants.CODE_SINGLE_QUOTE);
|
2012-06-26 10:46:43 +00:00
|
|
|
}
|
2014-05-28 11:35:45 +00:00
|
|
|
return new SuggestedWordInfo(sb.toString(), wordInfo.mScore, wordInfo.mKindAndFlags,
|
2013-08-20 09:00:21 +00:00
|
|
|
wordInfo.mSourceDict, wordInfo.mIndexOfTouchPointOfSecondWord,
|
2013-10-21 05:40:32 +00:00
|
|
|
wordInfo.mAutoCommitFirstWordConfidence);
|
2012-06-26 10:46:43 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|