Merge "Remove unused partial commit."

This commit is contained in:
Keisuke Kuroyanagi 2014-03-20 09:54:15 +00:00 committed by Android (Google) Code Review
commit 7c20f140e0
12 changed files with 21 additions and 124 deletions

View file

@ -161,9 +161,9 @@ public final class BinaryDictionary extends Dictionary {
private static native int getNextWordNative(long dict, int token, int[] outCodePoints); private static native int getNextWordNative(long dict, int token, int[] outCodePoints);
private static native void getSuggestionsNative(long dict, long proximityInfo, private static native void getSuggestionsNative(long dict, long proximityInfo,
long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times, long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times,
int[] pointerIds, int[] inputCodePoints, int inputSize, int commitPoint, int[] pointerIds, int[] inputCodePoints, int inputSize, int[] suggestOptions,
int[] suggestOptions, int[] prevWordCodePointArray, int[] outputSuggestionCount, int[] prevWordCodePointArray, int[] outputSuggestionCount, int[] outputCodePoints,
int[] outputCodePoints, int[] outputScores, int[] outputIndices, int[] outputTypes, int[] outputScores, int[] outputIndices, int[] outputTypes,
int[] outputAutoCommitFirstWordConfidence); int[] outputAutoCommitFirstWordConfidence);
private static native void addUnigramWordNative(long dict, int[] word, int probability, private static native void addUnigramWordNative(long dict, int[] word, int probability,
int[] shortcutTarget, int shortcutProbability, boolean isNotAWord, int[] shortcutTarget, int shortcutProbability, boolean isNotAWord,
@ -262,7 +262,7 @@ public final class BinaryDictionary extends Dictionary {
getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(), getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
getTraverseSession(sessionId).getSession(), ips.getXCoordinates(), getTraverseSession(sessionId).getSession(), ips.getXCoordinates(),
ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), mInputCodePoints, ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), mInputCodePoints,
inputSize, 0 /* commitPoint */, mNativeSuggestOptions.getOptions(), inputSize, mNativeSuggestOptions.getOptions(),
prevWordCodePointArray, mOutputSuggestionCount, mOutputCodePoints, mOutputScores, prevWordCodePointArray, mOutputSuggestionCount, mOutputCodePoints, mOutputScores,
mSpaceIndices, mOutputTypes, mOutputAutoCommitFirstWordConfidence); mSpaceIndices, mOutputTypes, mOutputAutoCommitFirstWordConfidence);
final int count = mOutputSuggestionCount[0]; final int count = mOutputSuggestionCount[0];

View file

@ -143,7 +143,7 @@ static int latinime_BinaryDictionary_getFormatVersion(JNIEnv *env, jclass clazz,
static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, jlong dict, static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, jlong dict,
jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray, jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray,
jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray, 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 prevWordCodePointsForBigrams, jintArray outSuggestionCount,
jintArray outCodePointsArray, jintArray outScoresArray, jintArray outSpaceIndicesArray, jintArray outCodePointsArray, jintArray outScoresArray, jintArray outSpaceIndicesArray,
jintArray outTypesArray, jintArray outAutoCommitFirstWordConfidenceArray) { jintArray outTypesArray, jintArray outAutoCommitFirstWordConfidenceArray) {
@ -220,7 +220,7 @@ static void latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz,
// TODO: Use SuggestionResults to return suggestions. // TODO: Use SuggestionResults to return suggestions.
count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates, count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints, times, pointerIds, inputCodePoints, inputSize, prevWordCodePoints,
prevWordCodePointsLength, commitPoint, &givenSuggestOptions, outputCodePoints, prevWordCodePointsLength, &givenSuggestOptions, outputCodePoints,
scores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence); scores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
} else { } else {
SuggestionResults suggestionResults(MAX_RESULTS); SuggestionResults suggestionResults(MAX_RESULTS);
@ -506,7 +506,7 @@ static const JNINativeMethod sMethods[] = {
}, },
{ {
const_cast<char *>("getSuggestionsNative"), const_cast<char *>("getSuggestionsNative"),
const_cast<char *>("(JJJ[I[I[I[I[III[I[I[I[I[I[I[I[I)V"), const_cast<char *>("(JJJ[I[I[I[I[II[I[I[I[I[I[I[I[I)V"),
reinterpret_cast<void *>(latinime_BinaryDictionary_getSuggestions) reinterpret_cast<void *>(latinime_BinaryDictionary_getSuggestions)
}, },
{ {

View file

@ -284,33 +284,6 @@ class DicNode {
return prevWordsLen + currentWordDepth > MAX_WORD_LENGTH - 3; 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 { void outputResult(int *dest) const {
const uint16_t prevWordLength = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(); const uint16_t prevWordLength = mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength();
const uint16_t currentDepth = getNodeCodePointCount(); const uint16_t currentDepth = getNodeCodePointCount();

View file

@ -28,37 +28,4 @@ const int DicNodesCache::LARGE_PRIORITY_QUEUE_CAPACITY = 310;
// Capacity for reducing memory footprint. // Capacity for reducing memory footprint.
const int DicNodesCache::SMALL_PRIORITY_QUEUE_CAPACITY = 100; 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<DicNode> 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<DicNode>::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 } // namespace latinime

View file

@ -76,8 +76,6 @@ class DicNodesCache {
moveNodesAndReturnReusableEmptyQueue(mNextActiveDicNodes, &mActiveDicNodes); moveNodesAndReturnReusableEmptyQueue(mNextActiveDicNodes, &mActiveDicNodes);
} }
DicNode *setCommitPoint(int commitPoint);
int activeSize() const { return mActiveDicNodes->getSize(); } int activeSize() const { return mActiveDicNodes->getSize(); }
int terminalSize() const { return mTerminalDicNodes->getSize(); } int terminalSize() const { return mTerminalDicNodes->getSize(); }
bool isLookAheadCorrectionInputIndex(const int inputIndex) const { bool isLookAheadCorrectionInputIndex(const int inputIndex) const {

View file

@ -27,11 +27,6 @@ class DicNodeStateInput {
DicNodeStateInput() {} DicNodeStateInput() {}
~DicNodeStateInput() {} ~DicNodeStateInput() {}
// TODO: Merge into DicNodeStatePrevWord::truncate
void truncate(const int commitPoint) {
mInputIndex[0] -= commitPoint;
}
void init() { void init() {
for (int i = 0; i < MAX_POINTER_COUNT_G; i++) { for (int i = 0; i < MAX_POINTER_COUNT_G; i++) {
// TODO: The initial value for mInputIndex should be -1? // TODO: The initial value for mInputIndex should be -1?

View file

@ -70,18 +70,6 @@ class DicNodeStatePrevWord {
mSecondWordFirstInputIndex = prevWordSecondWordFirstInputIndex; 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) { void setSecondWordFirstInputIndex(const int inputIndex) {
mSecondWordFirstInputIndex = inputIndex; mSecondWordFirstInputIndex = inputIndex;
} }
@ -111,18 +99,6 @@ class DicNodeStatePrevWord {
return mPrevWord[id]; 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 { const int *getPrevWordBuf() const {
return mPrevWord; return mPrevWord;
} }

View file

@ -45,7 +45,7 @@ Dictionary::Dictionary(JNIEnv *env, DictionaryStructureWithBufferPolicy::Structu
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession, int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, 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, const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const { int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
TimeKeeper::setCurrentTime(); TimeKeeper::setCurrentTime();
@ -54,7 +54,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
DicTraverseSession::initSessionInstance( DicTraverseSession::initSessionInstance(
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions); traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, result = mGestureSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, outWords, ycoordinates, times, pointerIds, inputCodePoints, inputSize, outWords,
outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence); outputScores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) { if (DEBUG_DICT) {
DUMP_RESULT(outWords, outputScores); DUMP_RESULT(outWords, outputScores);
@ -64,7 +64,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
DicTraverseSession::initSessionInstance( DicTraverseSession::initSessionInstance(
traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions); traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates, result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint, ycoordinates, times, pointerIds, inputCodePoints, inputSize,
outWords, outputScores, spaceIndices, outputTypes, outWords, outputScores, spaceIndices, outputTypes,
outputAutoCommitFirstWordConfidence); outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) { if (DEBUG_DICT) {

View file

@ -64,7 +64,7 @@ class Dictionary {
int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession, int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession,
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, 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, const SuggestOptions *const suggestOptions, int *outWords, int *outputScores,
int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const; int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const;

View file

@ -44,7 +44,7 @@ const int Suggest::MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE = 2;
*/ */
int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession, int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
int *inputXs, int *inputYs, int *times, int *pointerIds, int *inputCodePoints, 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 { int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
PROF_OPEN; PROF_OPEN;
PROF_START(0); PROF_START(0);
@ -54,7 +54,7 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
pointerIds, maxSpatialDistance, TRAVERSAL->getMaxPointerCount()); pointerIds, maxSpatialDistance, TRAVERSAL->getMaxPointerCount());
// TODO: Add the way to evaluate cache // TODO: Add the way to evaluate cache
initializeSearch(tSession, commitPoint); initializeSearch(tSession);
PROF_END(0); PROF_END(0);
PROF_START(1); 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 * 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. * 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()) { if (!traverseSession->getProximityInfoState(0)->isUsed()) {
return; return;
} }
// Never auto partial commit for now.
commitPoint = 0;
if (traverseSession->getInputSize() > MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE if (traverseSession->getInputSize() > MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE
&& traverseSession->isContinuousSuggestionPossible()) { && traverseSession->isContinuousSuggestionPossible()) {
if (commitPoint == 0) { // Continue suggestion
// Continue suggestion traverseSession->getDicTraverseCache()->continueSearch();
traverseSession->getDicTraverseCache()->continueSearch();
} else {
// Continue suggestion after partial commit.
DicNode *topDicNode =
traverseSession->getDicTraverseCache()->setCommitPoint(commitPoint);
traverseSession->setPrevWordPtNodePos(topDicNode->getPrevWordPtNodePos());
traverseSession->getDicTraverseCache()->continueSearch();
traverseSession->setPartiallyCommited();
}
} else { } else {
// Restart recognition at the root. // Restart recognition at the root.
traverseSession->resetCache(TRAVERSAL->getMaxCacheSize(traverseSession->getInputSize()), traverseSession->resetCache(TRAVERSAL->getMaxCacheSize(traverseSession->getInputSize()),

View file

@ -47,15 +47,15 @@ class Suggest : public SuggestInterface {
WEIGHTING(suggestPolicy ? suggestPolicy->getWeighting() : nullptr) {} WEIGHTING(suggestPolicy ? suggestPolicy->getWeighting() : nullptr) {}
AK_FORCE_INLINE virtual ~Suggest() {} AK_FORCE_INLINE virtual ~Suggest() {}
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint, int *times, int *pointerIds, int *inputCodePoints, int inputSize, int *outWords,
int *outWords, int *outputScores, int *outputIndices, int *outputTypes, int *outputScores, int *outputIndices, int *outputTypes,
int *outputAutoCommitFirstWordConfidence) const; int *outputAutoCommitFirstWordConfidence) const;
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest); DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest);
void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode, void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode,
const bool spaceSubstitution) const; const bool spaceSubstitution) const;
void initializeSearch(DicTraverseSession *traverseSession, int commitPoint) const; void initializeSearch(DicTraverseSession *traverseSession) const;
void expandCurrentDicNodes(DicTraverseSession *traverseSession) const; void expandCurrentDicNodes(DicTraverseSession *traverseSession) const;
void processTerminalDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; void processTerminalDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const;
void processExpandedDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; void processExpandedDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const;

View file

@ -27,8 +27,8 @@ class SuggestInterface {
public: public:
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs,
int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize, int *inputYs, int *times, int *pointerIds, int *inputCodePoints, int inputSize,
int commitPoint, int *outWords, int *outputScores, int *outputIndices, int *outWords, int *outputScores, int *outputIndices, int *outputTypes,
int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0; int *outputAutoCommitFirstWordConfidence) const = 0;
SuggestInterface() {} SuggestInterface() {}
virtual ~SuggestInterface() {} virtual ~SuggestInterface() {}
private: private: