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);
}
}
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();
}
}
Aggregations