Search in sources :

Example 6 with NgramContext

use of com.android.inputmethod.latin.NgramContext in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class AndroidSpellCheckerSession method onGetSuggestionsMultiple.

@Override
public SuggestionsInfo[] onGetSuggestionsMultiple(TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
    long ident = Binder.clearCallingIdentity();
    try {
        final int length = textInfos.length;
        final SuggestionsInfo[] retval = new SuggestionsInfo[length];
        for (int i = 0; i < length; ++i) {
            final CharSequence prevWord;
            if (sequentialWords && i > 0) {
                final TextInfo prevTextInfo = textInfos[i - 1];
                final CharSequence prevWordCandidate = TextInfoCompatUtils.getCharSequenceOrString(prevTextInfo);
                // Note that an empty string would be used to indicate the initial word
                // in the future.
                prevWord = TextUtils.isEmpty(prevWordCandidate) ? null : prevWordCandidate;
            } else {
                prevWord = null;
            }
            final NgramContext ngramContext = new NgramContext(new NgramContext.WordInfo(prevWord));
            final TextInfo textInfo = textInfos[i];
            retval[i] = onGetSuggestionsInternal(textInfo, ngramContext, suggestionsLimit);
            retval[i].setCookieAndSequence(textInfo.getCookie(), textInfo.getSequence());
        }
        return retval;
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : TextInfo(android.view.textservice.TextInfo) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SuggestionsInfo(android.view.textservice.SuggestionsInfo) NgramContext(com.android.inputmethod.latin.NgramContext)

Example 7 with NgramContext

use of com.android.inputmethod.latin.NgramContext in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class InputLogic method commitChosenWord.

/**
     * Commits the chosen word to the text field and saves it for later retrieval.
     *
     * @param settingsValues the current values of the settings.
     * @param chosenWord the word we want to commit.
     * @param commitType the type of the commit, as one of LastComposedWord.COMMIT_TYPE_*
     * @param separatorString the separator that's causing the commit, or NOT_A_SEPARATOR if none.
     */
private void commitChosenWord(final SettingsValues settingsValues, final String chosenWord, final int commitType, final String separatorString) {
    long startTimeMillis = 0;
    if (DebugFlags.DEBUG_ENABLED) {
        startTimeMillis = System.currentTimeMillis();
        Log.d(TAG, "commitChosenWord() : [" + chosenWord + "]");
    }
    final SuggestedWords suggestedWords = mSuggestedWords;
    // TODO: Locale should be determined based on context and the text given.
    final Locale locale = getDictionaryFacilitatorLocale();
    final CharSequence chosenWordWithSuggestions = chosenWord;
    //                suggestedWords, locale);
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "commitChosenWord() : " + runTimeMillis + " ms to run " + "SuggestionSpanUtils.getTextWithSuggestionSpan()");
        startTimeMillis = System.currentTimeMillis();
    }
    // When we are composing word, get n-gram context from the 2nd previous word because the
    // 1st previous word is the word to be committed. Otherwise get n-gram context from the 1st
    // previous word.
    final NgramContext ngramContext = mConnection.getNgramContextFromNthPreviousWord(settingsValues.mSpacingAndPunctuations, mWordComposer.isComposingWord() ? 2 : 1);
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "commitChosenWord() : " + runTimeMillis + " ms to run " + "Connection.getNgramContextFromNthPreviousWord()");
        Log.d(TAG, "commitChosenWord() : NgramContext = " + ngramContext);
        startTimeMillis = System.currentTimeMillis();
    }
    mConnection.commitText(chosenWordWithSuggestions, 1);
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "commitChosenWord() : " + runTimeMillis + " ms to run " + "Connection.commitText");
        startTimeMillis = System.currentTimeMillis();
    }
    // Add the word to the user history dictionary
    performAdditionToUserHistoryDictionary(settingsValues, chosenWord, ngramContext);
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "commitChosenWord() : " + runTimeMillis + " ms to run " + "performAdditionToUserHistoryDictionary()");
        startTimeMillis = System.currentTimeMillis();
    }
    // TODO: figure out here if this is an auto-correct or if the best word is actually
    // what user typed. Note: currently this is done much later in
    // LastComposedWord#didCommitTypedWord by string equality of the remembered
    // strings.
    mLastComposedWord = mWordComposer.commitWord(commitType, chosenWordWithSuggestions, separatorString, ngramContext);
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "commitChosenWord() : " + runTimeMillis + " ms to run " + "WordComposer.commitWord()");
        startTimeMillis = System.currentTimeMillis();
    }
}
Also used : Locale(java.util.Locale) SuggestedWords(com.android.inputmethod.latin.SuggestedWords) NgramContext(com.android.inputmethod.latin.NgramContext)

Aggregations

NgramContext (com.android.inputmethod.latin.NgramContext)7 SentenceSuggestionsInfo (android.view.textservice.SentenceSuggestionsInfo)2 SuggestionsInfo (android.view.textservice.SuggestionsInfo)2 WordInfo (com.android.inputmethod.latin.NgramContext.WordInfo)2 ArrayList (java.util.ArrayList)2 TargetApi (android.annotation.TargetApi)1 TextInfo (android.view.textservice.TextInfo)1 SuggestedWords (com.android.inputmethod.latin.SuggestedWords)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1