diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 544fd0319..0aa34e82e 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -161,9 +161,9 @@ public final class BinaryDictionary extends Dictionary { private static native int getNextWordNative(long dict, int token, int[] outCodePoints); private static native void getSuggestionsNative(long dict, long proximityInfo, long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times, - int[] pointerIds, int[] inputCodePoints, int inputSize, int commitPoint, - int[] suggestOptions, int[] prevWordCodePointArray, int[] outputSuggestionCount, - int[] outputCodePoints, int[] outputScores, int[] outputIndices, int[] outputTypes, + int[] pointerIds, int[] inputCodePoints, int inputSize, int[] suggestOptions, + int[] prevWordCodePointArray, int[] outputSuggestionCount, int[] outputCodePoints, + int[] outputScores, int[] outputIndices, int[] outputTypes, int[] outputAutoCommitFirstWordConfidence); private static native void addUnigramWordNative(long dict, int[] word, int probability, int[] shortcutTarget, int shortcutProbability, boolean isNotAWord, @@ -262,7 +262,7 @@ public final class BinaryDictionary extends Dictionary { getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(), getTraverseSession(sessionId).getSession(), ips.getXCoordinates(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), mInputCodePoints, - inputSize, 0 /* commitPoint */, mNativeSuggestOptions.getOptions(), + inputSize, mNativeSuggestOptions.getOptions(), prevWordCodePointArray, mOutputSuggestionCount, mOutputCodePoints, mOutputScores, mSpaceIndices, mOutputTypes, mOutputAutoCommitFirstWordConfidence); final int count = mOutputSuggestionCount[0]; diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index eec354abc..ac0b4ab15 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -143,7 +143,7 @@ static int latinime_BinaryDictionary_getFormatVersion(JNIEnv *env, jclass clazz, static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, jlong dict, jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray, jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray, - jintArray inputCodePointsArray, jint inputSize, jint commitPoint, jintArray suggestOptions, + jintArray inputCodePointsArray, jint inputSize, jintArray suggestOptions, jintArray prevWordCodePointsForBigrams, jintArray outSuggestionCount, jintArray outCodePointsArray, jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outTypesArray, jintArray outAutoCommitFirstWordConfidenceArray) { @@ -220,7 +220,7 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, // TODO: Use SuggestionResults to return suggestions. count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates, times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints, - prevWordCodePointsLength, commitPoint, &givenSuggestOptions, outputCodePoints, + prevWordCodePointsLength, &givenSuggestOptions, outputCodePoints, scores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence); } else { SuggestionResults suggestionResults(MAX_RESULTS); @@ -506,7 +506,7 @@ static const JNINativeMethod sMethods[] = { }, { const_cast("getSuggestionsNative"), - const_cast("(JJJ[I[I[I[I[III[I[I[I[I[I[I[I[I)V"), + const_cast("(JJJ[I[I[I[I[II[I[I[I[I[I[I[I[I)V"), reinterpret_cast(latinime_BinaryDictionary_getSuggestions) }, { diff --git a/native/jni/src/suggest/core/dicnode/dic_node.h b/native/jni/src/suggest/core/dicnode/dic_node.h index 82b738d36..ae228fb98 100644 --- a/native/jni/src/suggest/core/dicnode/dic_node.h +++ b/native/jni/src/suggest/core/dicnode/dic_node.h @@ -284,33 +284,6 @@ class DicNode { return prevWordsLen + currentWordDepth > MAX_WORD_LENGTH - 3; } - // TODO: This may be defective. Needs to be revised. - bool truncateNode(const DicNode *const topNode, const int inputCommitPoint) { - const int prevWordLenOfTop = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(); - int newPrevWordStartIndex = inputCommitPoint; - int charCount = 0; - // Find new word start index - for (int i = 0; i < prevWordLenOfTop; ++i) { - const int c = mDicNodeState.mDicNodeStatePrevWord.getPrevWordCodePointAt(i); - // TODO: Check other separators. - if (c != KEYCODE_SPACE && c != KEYCODE_SINGLE_QUOTE) { - if (charCount == inputCommitPoint) { - newPrevWordStartIndex = i; - break; - } - ++charCount; - } - } - if (!mDicNodeState.mDicNodeStatePrevWord.startsWith( - &topNode->mDicNodeState.mDicNodeStatePrevWord, newPrevWordStartIndex - 1)) { - // Node mismatch. - return false; - } - mDicNodeState.mDicNodeStateInput.truncate(inputCommitPoint); - mDicNodeState.mDicNodeStatePrevWord.truncate(newPrevWordStartIndex); - return true; - } - void outputResult(int *dest) const { const uint16_t prevWordLength = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(); const uint16_t currentDepth = getNodeCodePointCount(); diff --git a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.cpp b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.cpp index b6be47e90..ef4a6b5d8 100644 --- a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.cpp +++ b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.cpp @@ -28,37 +28,4 @@ const int DicNodesCache::LARGE_PRIORITY_QUEUE_CAPACITY = 310; // Capacity for reducing memory footprint. const int DicNodesCache::SMALL_PRIORITY_QUEUE_CAPACITY = 100; -/** - * Truncates all of the dicNodes so that they start at the given commit point. - * Only called for multi-word typing input. - */ -DicNode *DicNodesCache::setCommitPoint(int commitPoint) { - std::list dicNodesList; - while (mCachedDicNodesForContinuousSuggestion->getSize() > 0) { - DicNode dicNode; - mCachedDicNodesForContinuousSuggestion->copyPop(&dicNode); - dicNodesList.push_front(dicNode); - } - - // Get the starting words of the top scoring dicNode (last dicNode popped from priority queue) - // up to the commit point. These words have already been committed to the text view. - DicNode *topDicNode = &dicNodesList.front(); - DicNode topDicNodeCopy; - DicNodeUtils::initByCopy(topDicNode, &topDicNodeCopy); - - // Keep only those dicNodes that match the same starting words. - std::list::iterator iter; - for (iter = dicNodesList.begin(); iter != dicNodesList.end(); iter++) { - DicNode *dicNode = &*iter; - if (dicNode->truncateNode(&topDicNodeCopy, commitPoint)) { - mCachedDicNodesForContinuousSuggestion->copyPush(dicNode); - } else { - // Top dicNode should be reprocessed. - ASSERT(dicNode != topDicNode); - DicNode::managedDelete(dicNode); - } - } - mInputIndex -= commitPoint; - return topDicNode; -} } // namespace latinime diff --git a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h index c31c056f5..d4769e739 100644 --- a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h +++ b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h @@ -76,8 +76,6 @@ class DicNodesCache { moveNodesAndReturnReusableEmptyQueue(mNextActiveDicNodes, &mActiveDicNodes); } - DicNode *setCommitPoint(int commitPoint); - int activeSize() const { return mActiveDicNodes->getSize(); } int terminalSize() const { return mTerminalDicNodes->getSize(); } bool isLookAheadCorrectionInputIndex(const int inputIndex) const { diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_input.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_input.h index 3d788114f..03042a8a7 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_input.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_input.h @@ -27,11 +27,6 @@ class DicNodeStateInput { DicNodeStateInput() {} ~DicNodeStateInput() {} - // TODO: Merge into DicNodeStatePrevWord::truncate - void truncate(const int commitPoint) { - mInputIndex[0] -= commitPoint; - } - void init() { for (int i = 0; i < MAX_POINTER_COUNT_G; i++) { // TODO: The initial value for mInputIndex should be -1? diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h index f2b1ce8f7..409841e2d 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h @@ -70,18 +70,6 @@ class DicNodeStatePrevWord { mSecondWordFirstInputIndex = prevWordSecondWordFirstInputIndex; } - void truncate(const int offset) { - // TODO: memmove - if (mPrevWordLength < offset) { - memset(mPrevWord, 0, sizeof(mPrevWord)); - mPrevWordLength = 0; - return; - } - const int newPrevWordLength = mPrevWordLength - offset; - memmove(mPrevWord, &mPrevWord[offset], newPrevWordLength * sizeof(mPrevWord[0])); - mPrevWordLength = newPrevWordLength; - } - void setSecondWordFirstInputIndex(const int inputIndex) { mSecondWordFirstInputIndex = inputIndex; } @@ -111,18 +99,6 @@ class DicNodeStatePrevWord { return mPrevWord[id]; } - bool startsWith(const DicNodeStatePrevWord *const prefix, const int prefixLen) const { - if (prefixLen > mPrevWordLength) { - return false; - } - for (int i = 0; i < prefixLen; ++i) { - if (mPrevWord[i] != prefix->mPrevWord[i]) { - return false; - } - } - return true; - } - const int *getPrevWordBuf() const { return mPrevWord; } diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index c26e3aad6..07b07f725 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -45,7 +45,7 @@ Dictionary::Dictionary(JNIEnv *env, DictionaryStructureWithBufferPolicy::Structu int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession, int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, - int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint, + int inputSize, int *prevWordCodePoints, int prevWordLength, const SuggestOptions *const suggestOptions, int *outWords, int *outputScores, int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const { TimeKeeper::setCurrentTime(); @@ -54,7 +54,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession DicTraverseSession::initSessionInstance( traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions); result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, - ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords, + ycoordinates, times, pointerIds, inputCodePoints, inputSize, outWords, outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence); if (DEBUG_DICT) { DUMP_RESULT(outWords, outputScores); @@ -64,7 +64,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession DicTraverseSession::initSessionInstance( traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions); result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, - ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, + ycoordinates, times, pointerIds, inputCodePoints, inputSize, outWords, outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence); if (DEBUG_DICT) { diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index ce032fceb..4d482e742 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -64,7 +64,7 @@ class Dictionary { int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession, int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, - int inputSize, int *prevWordCodePoints, int prevWordLength, int commitPoint, + int inputSize, int *prevWordCodePoints, int prevWordLength, const SuggestOptions *const suggestOptions, int *outWords, int *outputScores, int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const; diff --git a/native/jni/src/suggest/core/suggest.cpp b/native/jni/src/suggest/core/suggest.cpp index f60a210d4..f6de571a8 100644 --- a/native/jni/src/suggest/core/suggest.cpp +++ b/native/jni/src/suggest/core/suggest.cpp @@ -44,7 +44,7 @@ const int Suggest::MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE = 2; */ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints, - int inputSize, int commitPoint, int *outWords, int *outputScores, int *outputIndices, + int inputSize, int *outWords, int *outputScores, int *outputIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const { PROF_OPEN; PROF_START(0); @@ -54,7 +54,7 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession, pointerIds, maxSpatialDistance, TRAVERSAL->getMaxPointerCount()); // TODO: Add the way to evaluate cache - initializeSearch(tSession, commitPoint); + initializeSearch(tSession); PROF_END(0); PROF_START(1); @@ -77,27 +77,15 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession, * Initializes the search at the root of the lexicon trie. Note that when possible the search will * continue suggestion from where it left off during the last call. */ -void Suggest::initializeSearch(DicTraverseSession *traverseSession, int commitPoint) const { +void Suggest::initializeSearch(DicTraverseSession *traverseSession) const { if (!traverseSession->getProximityInfoState(0)->isUsed()) { return; } - // Never auto partial commit for now. - commitPoint = 0; - if (traverseSession->getInputSize() > MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE && traverseSession->isContinuousSuggestionPossible()) { - if (commitPoint == 0) { - // Continue suggestion - traverseSession->getDicTraverseCache()->continueSearch(); - } else { - // Continue suggestion after partial commit. - DicNode *topDicNode = - traverseSession->getDicTraverseCache()->setCommitPoint(commitPoint); - traverseSession->setPrevWordPtNodePos(topDicNode->getPrevWordPtNodePos()); - traverseSession->getDicTraverseCache()->continueSearch(); - traverseSession->setPartiallyCommited(); - } + // Continue suggestion + traverseSession->getDicTraverseCache()->continueSearch(); } else { // Restart recognition at the root. traverseSession->resetCache(TRAVERSAL->getMaxCacheSize(traverseSession->getInputSize()), diff --git a/native/jni/src/suggest/core/suggest.h b/native/jni/src/suggest/core/suggest.h index c42986ad6..33ea0b658 100644 --- a/native/jni/src/suggest/core/suggest.h +++ b/native/jni/src/suggest/core/suggest.h @@ -47,15 +47,15 @@ class Suggest : public SuggestInterface { WEIGHTING(suggestPolicy ? suggestPolicy->getWeighting() : nullptr) {} AK_FORCE_INLINE virtual ~Suggest() {} int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, - int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint, - int *outWords, int *outputScores, int *outputIndices, int *outputTypes, + int *times, int *pointerIds, int *inputCodePoints, int inputSize, int *outWords, + int *outputScores, int *outputIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const; private: DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest); void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode, const bool spaceSubstitution) const; - void initializeSearch(DicTraverseSession *traverseSession, int commitPoint) const; + void initializeSearch(DicTraverseSession *traverseSession) const; void expandCurrentDicNodes(DicTraverseSession *traverseSession) const; void processTerminalDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; void processExpandedDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; diff --git a/native/jni/src/suggest/core/suggest_interface.h b/native/jni/src/suggest/core/suggest_interface.h index 9a0758085..f10db830f 100644 --- a/native/jni/src/suggest/core/suggest_interface.h +++ b/native/jni/src/suggest/core/suggest_interface.h @@ -27,8 +27,8 @@ class SuggestInterface { public: virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize, - int commitPoint, int *outWords, int *outputScores, int *outputIndices, - int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0; + int *outWords, int *outputScores, int *outputIndices, int *outputTypes, + int *outputAutoCommitFirstWordConfidence) const = 0; SuggestInterface() {} virtual ~SuggestInterface() {} private: