use of com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class BinaryDictionary method getSuggestions.
@Override
public ArrayList<SuggestedWordInfo> getSuggestions(final ComposedData composedData, final NgramContext ngramContext, final long proximityInfoHandle, final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId, final float weightForLocale, final float[] inOutWeightOfLangModelVsSpatialModel) {
if (!isValidDictionary()) {
return null;
}
final DicTraverseSession session = getTraverseSession(sessionId);
Arrays.fill(session.mInputCodePoints, Constants.NOT_A_CODE);
ngramContext.outputToArray(session.mPrevWordCodePointArrays, session.mIsBeginningOfSentenceArray);
final InputPointers inputPointers = composedData.mInputPointers;
final boolean isGesture = composedData.mIsBatchMode;
final int inputSize;
if (!isGesture) {
inputSize = composedData.copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(session.mInputCodePoints);
if (inputSize < 0) {
return null;
}
} else {
inputSize = inputPointers.getPointerSize();
}
session.mNativeSuggestOptions.setUseFullEditDistance(mUseFullEditDistance);
session.mNativeSuggestOptions.setIsGesture(isGesture);
session.mNativeSuggestOptions.setBlockOffensiveWords(settingsValuesForSuggestion.mBlockPotentiallyOffensive);
session.mNativeSuggestOptions.setWeightForLocale(weightForLocale);
if (inOutWeightOfLangModelVsSpatialModel != null) {
session.mInputOutputWeightOfLangModelVsSpatialModel[0] = inOutWeightOfLangModelVsSpatialModel[0];
} else {
session.mInputOutputWeightOfLangModelVsSpatialModel[0] = Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL;
}
// TOOD: Pass multiple previous words information for n-gram.
getSuggestionsNative(mNativeDict, proximityInfoHandle, getTraverseSession(sessionId).getSession(), inputPointers.getXCoordinates(), inputPointers.getYCoordinates(), inputPointers.getTimes(), inputPointers.getPointerIds(), session.mInputCodePoints, inputSize, session.mNativeSuggestOptions.getOptions(), session.mPrevWordCodePointArrays, session.mIsBeginningOfSentenceArray, ngramContext.getPrevWordCount(), session.mOutputSuggestionCount, session.mOutputCodePoints, session.mOutputScores, session.mSpaceIndices, session.mOutputTypes, session.mOutputAutoCommitFirstWordConfidence, session.mInputOutputWeightOfLangModelVsSpatialModel);
if (inOutWeightOfLangModelVsSpatialModel != null) {
inOutWeightOfLangModelVsSpatialModel[0] = session.mInputOutputWeightOfLangModelVsSpatialModel[0];
}
final int count = session.mOutputSuggestionCount[0];
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
for (int j = 0; j < count; ++j) {
final int start = j * DICTIONARY_MAX_WORD_LENGTH;
int len = 0;
while (len < DICTIONARY_MAX_WORD_LENGTH && session.mOutputCodePoints[start + len] != 0) {
++len;
}
if (len > 0) {
suggestions.add(new SuggestedWordInfo(new String(session.mOutputCodePoints, start, len), "", /* prevWordsContext */
(int) (session.mOutputScores[j] * weightForLocale), session.mOutputTypes[j], this, /* sourceDict */
session.mSpaceIndices[j], /* indexOfTouchPointOfSecondWord */
session.mOutputAutoCommitFirstWordConfidence[0]));
}
}
return suggestions;
}
use of com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class DictionaryFacilitatorImpl method getSuggestionResults.
// TODO: Revise the way to fusion suggestion results.
@Override
@Nonnull
public SuggestionResults getSuggestionResults(ComposedData composedData, NgramContext ngramContext, @Nonnull final Keyboard keyboard, SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId, int inputStyle) {
long proximityInfoHandle = keyboard.getProximityInfo().getNativeProximityInfo();
final SuggestionResults suggestionResults = new SuggestionResults(SuggestedWords.MAX_SUGGESTIONS, ngramContext.isBeginningOfSentenceContext(), false);
final float[] weightOfLangModelVsSpatialModel = new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL };
for (final String dictType : ALL_DICTIONARY_TYPES) {
final Dictionary dictionary = mDictionaryGroup.getDict(dictType);
if (null == dictionary)
continue;
final float weightForLocale = composedData.mIsBatchMode ? mDictionaryGroup.mWeightForGesturingInLocale : mDictionaryGroup.mWeightForTypingInLocale;
final ArrayList<SuggestedWordInfo> dictionarySuggestions = dictionary.getSuggestions(composedData, ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId, weightForLocale, weightOfLangModelVsSpatialModel);
if (null == dictionarySuggestions)
continue;
suggestionResults.addAll(dictionarySuggestions);
if (null != suggestionResults.mRawSuggestions) {
suggestionResults.mRawSuggestions.addAll(dictionarySuggestions);
}
}
return suggestionResults;
}
use of com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class Suggest method getTransformedSuggestedWordInfoList.
private static ArrayList<SuggestedWordInfo> getTransformedSuggestedWordInfoList(final WordComposer wordComposer, final SuggestionResults results, final int trailingSingleQuotesCount, final Locale defaultLocale) {
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 Locale wordLocale = wordInfo.mSourceDict.mLocale;
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(wordInfo, null == wordLocale ? defaultLocale : wordLocale, shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
suggestionsContainer.set(i, transformedWordInfo);
}
}
return suggestionsContainer;
}
use of com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class Suggest method getSuggestedWordsForBatchInput.
// Retrieves suggestions for the batch input
// and calls the callback function with the suggestions.
private void getSuggestedWordsForBatchInput(final WordComposer wordComposer, final NgramContext ngramContext, final Keyboard keyboard, final SettingsValuesForSuggestion settingsValuesForSuggestion, final int inputStyle, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(wordComposer.getComposedDataSnapshot(), ngramContext, keyboard, settingsValuesForSuggestion, SESSION_ID_GESTURE, inputStyle);
// For transforming words that don't come from a dictionary, because it's our best bet
final Locale locale = mDictionaryFacilitator.getLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer = new ArrayList<>(suggestionResults);
final int suggestionsCount = suggestionsContainer.size();
final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock();
final boolean isAllUpperCase = wordComposer.isAllUpperCase();
if (isFirstCharCapitalized || isAllUpperCase) {
for (int i = 0; i < suggestionsCount; ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
final Locale wordlocale = wordInfo.mSourceDict.mLocale;
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(wordInfo, null == wordlocale ? locale : wordlocale, isAllUpperCase, isFirstCharCapitalized, 0);
suggestionsContainer.set(i, transformedWordInfo);
}
}
if (SHOULD_REMOVE_PREVIOUSLY_REJECTED_SUGGESTION && suggestionsContainer.size() > 1 && TextUtils.equals(suggestionsContainer.get(0).mWord, wordComposer.getRejectedBatchModeSuggestion())) {
final SuggestedWordInfo rejected = suggestionsContainer.remove(0);
suggestionsContainer.add(1, rejected);
}
SuggestedWordInfo.removeDups(null, /* typedWord */
suggestionsContainer);
// TODO: Find a more robust way to detect distracters.
for (int i = suggestionsContainer.size() - 1; i >= 0; --i) {
if (suggestionsContainer.get(i).mScore < SUPPRESS_SUGGEST_THRESHOLD) {
suggestionsContainer.remove(i);
}
}
// 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).
// Note that because this method is never used to get predictions, there is no need to
// modify inputType such in getSuggestedWordsForNonBatchInput.
final SuggestedWordInfo pseudoTypedWordInfo = suggestionsContainer.isEmpty() ? null : suggestionsContainer.get(0);
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, suggestionResults.mRawSuggestions, pseudoTypedWordInfo, true, /* typedWordValid */
false, /* willAutoCorrect */
false, /* isObsoleteSuggestions */
inputStyle, sequenceNumber));
}
use of com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class InputLogic method retrieveOlderSuggestions.
/**
* Make a {@link com.android.inputmethod.latin.SuggestedWords} object containing a typed word
* and obsolete suggestions.
* See {@link com.android.inputmethod.latin.SuggestedWords#getTypedWordAndPreviousSuggestions(
* SuggestedWordInfo, com.android.inputmethod.latin.SuggestedWords)}.
* @param typedWordInfo The typed word as a SuggestedWordInfo.
* @param previousSuggestedWords The previously suggested words.
* @return Obsolete suggestions with the newly typed word.
*/
static SuggestedWords retrieveOlderSuggestions(final SuggestedWordInfo typedWordInfo, final SuggestedWords previousSuggestedWords) {
final SuggestedWords oldSuggestedWords = previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.getEmptyInstance() : previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions(typedWordInfo, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, null, /* rawSuggestions */
typedWordInfo, false, /* typedWordValid */
false, /* hasAutoCorrectionCandidate */
true, /* isObsoleteSuggestions */
oldSuggestedWords.mInputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
}
Aggregations