am 4e17b42d: Output input index of second word\'s first char.

* commit '4e17b42d0fd104ec2cd3a79db2473863228ecb62':
  Output input index of second word's first char.
main
Keisuke Kuroyanagi 2013-09-17 04:56:05 -07:00 committed by Android Git Automerger
commit 97f53a9fe7
6 changed files with 63 additions and 31 deletions

View File

@ -143,7 +143,7 @@ class DicNode {
dicNode->mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(), dicNode->mDicNodeState.mDicNodeStatePrevWord.getPrevWordLength(),
dicNode->getOutputWordBuf(), dicNode->getOutputWordBuf(),
dicNode->mDicNodeProperties.getDepth(), dicNode->mDicNodeProperties.getDepth(),
dicNode->mDicNodeState.mDicNodeStatePrevWord.mPrevSpacePositions, dicNode->mDicNodeState.mDicNodeStatePrevWord.getSecondWordFirstInputIndex(),
mDicNodeState.mDicNodeStateInput.getInputIndex(0) /* lastInputIndex */); mDicNodeState.mDicNodeStateInput.getInputIndex(0) /* lastInputIndex */);
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
} }
@ -321,8 +321,13 @@ class DicNode {
DUMP_WORD_AND_SCORE("OUTPUT"); DUMP_WORD_AND_SCORE("OUTPUT");
} }
void outputSpacePositionsResult(int *spaceIndices) const { int getSecondWordFirstInputIndex(const ProximityInfoState *const pInfoState) const {
mDicNodeState.mDicNodeStatePrevWord.outputSpacePositions(spaceIndices); const int inputIndex = mDicNodeState.mDicNodeStatePrevWord.getSecondWordFirstInputIndex();
if (inputIndex == NOT_AN_INDEX) {
return NOT_AN_INDEX;
} else {
return pInfoState->getInputIndexOfSampledPoint(inputIndex);
}
} }
bool hasMultipleWords() const { bool hasMultipleWords() const {
@ -573,7 +578,11 @@ class DicNode {
} }
} }
AK_FORCE_INLINE void updateInputIndexG(DicNode_InputStateG *inputStateG) { AK_FORCE_INLINE void updateInputIndexG(const DicNode_InputStateG *const inputStateG) {
if (mDicNodeState.mDicNodeStatePrevWord.getPrevWordCount() == 1 && isFirstLetter()) {
mDicNodeState.mDicNodeStatePrevWord.setSecondWordFirstInputIndex(
inputStateG->mInputIndex);
}
mDicNodeState.mDicNodeStateInput.updateInputIndexG(inputStateG->mPointerId, mDicNodeState.mDicNodeStateInput.updateInputIndexG(inputStateG->mPointerId,
inputStateG->mInputIndex, inputStateG->mPrevCodePoint, inputStateG->mInputIndex, inputStateG->mPrevCodePoint,
inputStateG->mTerminalDiffCost, inputStateG->mRawLength); inputStateG->mTerminalDiffCost, inputStateG->mRawLength);

View File

@ -22,6 +22,7 @@
#include "defines.h" #include "defines.h"
#include "suggest/core/dicnode/dic_node_utils.h" #include "suggest/core/dicnode/dic_node_utils.h"
#include "suggest/core/layout/proximity_info_state.h"
namespace latinime { namespace latinime {
@ -29,9 +30,8 @@ class DicNodeStatePrevWord {
public: public:
AK_FORCE_INLINE DicNodeStatePrevWord() AK_FORCE_INLINE DicNodeStatePrevWord()
: mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0), : mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0),
mPrevWordNodePos(NOT_A_DICT_POS) { mPrevWordNodePos(NOT_A_DICT_POS), mSecondWordFirstInputIndex(NOT_AN_INDEX) {
memset(mPrevWord, 0, sizeof(mPrevWord)); memset(mPrevWord, 0, sizeof(mPrevWord));
memset(mPrevSpacePositions, 0, sizeof(mPrevSpacePositions));
} }
virtual ~DicNodeStatePrevWord() {} virtual ~DicNodeStatePrevWord() {}
@ -42,7 +42,7 @@ class DicNodeStatePrevWord {
mPrevWordStart = 0; mPrevWordStart = 0;
mPrevWordProbability = -1; mPrevWordProbability = -1;
mPrevWordNodePos = NOT_A_DICT_POS; mPrevWordNodePos = NOT_A_DICT_POS;
memset(mPrevSpacePositions, 0, sizeof(mPrevSpacePositions)); mSecondWordFirstInputIndex = NOT_AN_INDEX;
} }
void init(const int prevWordNodePos) { void init(const int prevWordNodePos) {
@ -51,7 +51,7 @@ class DicNodeStatePrevWord {
mPrevWordStart = 0; mPrevWordStart = 0;
mPrevWordProbability = -1; mPrevWordProbability = -1;
mPrevWordNodePos = prevWordNodePos; mPrevWordNodePos = prevWordNodePos;
memset(mPrevSpacePositions, 0, sizeof(mPrevSpacePositions)); mSecondWordFirstInputIndex = NOT_AN_INDEX;
} }
// Init by copy // Init by copy
@ -61,14 +61,14 @@ class DicNodeStatePrevWord {
mPrevWordStart = prevWord->mPrevWordStart; mPrevWordStart = prevWord->mPrevWordStart;
mPrevWordProbability = prevWord->mPrevWordProbability; mPrevWordProbability = prevWord->mPrevWordProbability;
mPrevWordNodePos = prevWord->mPrevWordNodePos; mPrevWordNodePos = prevWord->mPrevWordNodePos;
mSecondWordFirstInputIndex = prevWord->mSecondWordFirstInputIndex;
memcpy(mPrevWord, prevWord->mPrevWord, prevWord->mPrevWordLength * sizeof(mPrevWord[0])); memcpy(mPrevWord, prevWord->mPrevWord, prevWord->mPrevWordLength * sizeof(mPrevWord[0]));
memcpy(mPrevSpacePositions, prevWord->mPrevSpacePositions, sizeof(mPrevSpacePositions));
} }
void init(const int16_t prevWordCount, const int16_t prevWordProbability, void init(const int16_t prevWordCount, const int16_t prevWordProbability,
const int prevWordNodePos, const int *const src0, const int16_t length0, const int prevWordNodePos, const int *const src0, const int16_t length0,
const int *const src1, const int16_t length1, const int *const prevSpacePositions, const int *const src1, const int16_t length1,
const int lastInputIndex) { const int prevWordSecondWordFirstInputIndex, const int lastInputIndex) {
mPrevWordCount = min(prevWordCount, static_cast<int16_t>(MAX_RESULTS)); mPrevWordCount = min(prevWordCount, static_cast<int16_t>(MAX_RESULTS));
mPrevWordProbability = prevWordProbability; mPrevWordProbability = prevWordProbability;
mPrevWordNodePos = prevWordNodePos; mPrevWordNodePos = prevWordNodePos;
@ -80,8 +80,7 @@ class DicNodeStatePrevWord {
mPrevWord[twoWordsLen] = KEYCODE_SPACE; mPrevWord[twoWordsLen] = KEYCODE_SPACE;
mPrevWordStart = length0; mPrevWordStart = length0;
mPrevWordLength = static_cast<int16_t>(twoWordsLen + 1); mPrevWordLength = static_cast<int16_t>(twoWordsLen + 1);
memcpy(mPrevSpacePositions, prevSpacePositions, sizeof(mPrevSpacePositions)); mSecondWordFirstInputIndex = prevWordSecondWordFirstInputIndex;
mPrevSpacePositions[mPrevWordCount - 1] = lastInputIndex;
} }
void truncate(const int offset) { void truncate(const int offset) {
@ -96,11 +95,12 @@ class DicNodeStatePrevWord {
mPrevWordLength = newPrevWordLength; mPrevWordLength = newPrevWordLength;
} }
void outputSpacePositions(int *spaceIndices) const { void setSecondWordFirstInputIndex(const int inputIndex) {
// Convert uint16_t to int mSecondWordFirstInputIndex = inputIndex;
for (int i = 0; i < MAX_RESULTS; i++) { }
spaceIndices[i] = mPrevSpacePositions[i];
} int getSecondWordFirstInputIndex() const {
return mSecondWordFirstInputIndex;
} }
// TODO: remove // TODO: remove
@ -138,8 +138,6 @@ class DicNodeStatePrevWord {
// TODO: Move to private // TODO: Move to private
int mPrevWord[MAX_WORD_LENGTH]; int mPrevWord[MAX_WORD_LENGTH];
// TODO: Move to private
int mPrevSpacePositions[MAX_RESULTS];
private: private:
// Caution!!! // Caution!!!
@ -150,6 +148,7 @@ class DicNodeStatePrevWord {
int16_t mPrevWordStart; int16_t mPrevWordStart;
int16_t mPrevWordProbability; int16_t mPrevWordProbability;
int mPrevWordNodePos; int mPrevWordNodePos;
int mSecondWordFirstInputIndex;
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_DIC_NODE_STATE_PREVWORD_H #endif // LATINIME_DIC_NODE_STATE_PREVWORD_H

View File

@ -130,6 +130,10 @@ class ProximityInfoState {
return mSampledInputYs[index]; return mSampledInputYs[index];
} }
int getInputIndexOfSampledPoint(const int sampledIndex) const {
return mSampledInputIndice[sampledIndex];
}
bool hasSpaceProximity(const int index) const; bool hasSpaceProximity(const int index) const;
int getLengthCache(const int index) const { int getLengthCache(const int index) const {

View File

@ -113,7 +113,9 @@ class DicTraverseSession {
if (usedPointerCount != 1) { if (usedPointerCount != 1) {
return false; return false;
} }
*pointerId = usedPointerId; if (pointerId) {
*pointerId = usedPointerId;
}
return true; return true;
} }

View File

@ -117,7 +117,7 @@ void Suggest::initializeSearch(DicTraverseSession *traverseSession, int commitPo
* Outputs the final list of suggestions (i.e., terminal nodes). * Outputs the final list of suggestions (i.e., terminal nodes).
*/ */
int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequencies, int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequencies,
int *outputCodePoints, int *spaceIndices, int *outputTypes) const { int *outputCodePoints, int *outputIndicesToPartialCommit, int *outputTypes) const {
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING #if DEBUG_EVALUATE_MOST_PROBABLE_STRING
const int terminalSize = 0; const int terminalSize = 0;
#else #else
@ -139,6 +139,7 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
SCORING->getMostProbableString(traverseSession, terminalSize, languageWeight, SCORING->getMostProbableString(traverseSession, terminalSize, languageWeight,
&outputCodePoints[0], &outputTypes[0], &frequencies[0]); &outputCodePoints[0], &outputTypes[0], &frequencies[0]);
if (hasMostProbableString) { if (hasMostProbableString) {
outputIndicesToPartialCommit[outputWordIndex] = NOT_AN_INDEX;
++outputWordIndex; ++outputWordIndex;
} }
@ -160,6 +161,9 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
|| (traverseSession->getInputSize() || (traverseSession->getInputSize()
>= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT >= MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT
&& terminals[0].hasMultipleWords())) : false; && terminals[0].hasMultipleWords())) : false;
// TODO: have partial commit work even with multiple pointers.
const bool outputSecondWordFirstLetterInputIndex =
traverseSession->isOnlyOnePointerUsed(0 /* pointerId */);
// Output suggestion results here // Output suggestion results here
for (int terminalIndex = 0; terminalIndex < terminalSize && outputWordIndex < MAX_RESULTS; for (int terminalIndex = 0; terminalIndex < terminalSize && outputWordIndex < MAX_RESULTS;
++terminalIndex) { ++terminalIndex) {
@ -194,18 +198,21 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
terminalDicNode->isExactMatch() terminalDicNode->isExactMatch()
|| (forceCommitMultiWords && terminalDicNode->hasMultipleWords()) || (forceCommitMultiWords && terminalDicNode->hasMultipleWords())
|| (isValidWord && SCORING->doesAutoCorrectValidWord())); || (isValidWord && SCORING->doesAutoCorrectValidWord()));
maxScore = max(maxScore, finalScore); if (maxScore < finalScore && isValidWord) {
maxScore = finalScore;
// TODO: Implement a smarter auto-commit method for handling multi-word suggestions.
// Index for top typing suggestion should be 0.
if (isValidWord && outputWordIndex == 0) {
terminalDicNode->outputSpacePositionsResult(spaceIndices);
} }
// Don't output invalid words. However, we still need to submit their shortcuts if any. // Don't output invalid words. However, we still need to submit their shortcuts if any.
if (isValidWord) { if (isValidWord) {
outputTypes[outputWordIndex] = Dictionary::KIND_CORRECTION | outputTypeFlags; outputTypes[outputWordIndex] = Dictionary::KIND_CORRECTION | outputTypeFlags;
frequencies[outputWordIndex] = finalScore; frequencies[outputWordIndex] = finalScore;
if (outputSecondWordFirstLetterInputIndex) {
outputIndicesToPartialCommit[outputWordIndex] =
terminalDicNode->getSecondWordFirstInputIndex(
traverseSession->getProximityInfoState(0));
} else {
outputIndicesToPartialCommit[outputWordIndex] = NOT_AN_INDEX;
}
// Populate the outputChars array with the suggested word. // Populate the outputChars array with the suggested word.
const int startIndex = outputWordIndex * MAX_WORD_LENGTH; const int startIndex = outputWordIndex * MAX_WORD_LENGTH;
terminalDicNode->outputResult(&outputCodePoints[startIndex]); terminalDicNode->outputResult(&outputCodePoints[startIndex]);
@ -220,8 +227,19 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
// Shortcut is not supported for multiple words suggestions. // Shortcut is not supported for multiple words suggestions.
// TODO: Check shortcuts during traversal for multiple words suggestions. // TODO: Check shortcuts during traversal for multiple words suggestions.
const bool sameAsTyped = TRAVERSAL->sameAsTyped(traverseSession, terminalDicNode); const bool sameAsTyped = TRAVERSAL->sameAsTyped(traverseSession, terminalDicNode);
outputWordIndex = ShortcutUtils::outputShortcuts(&shortcutIt, outputWordIndex, const int updatedOutputWordIndex = ShortcutUtils::outputShortcuts(&shortcutIt,
finalScore, outputCodePoints, frequencies, outputTypes, sameAsTyped); outputWordIndex, finalScore, outputCodePoints, frequencies, outputTypes,
sameAsTyped);
const int secondWordFirstInputIndex = terminalDicNode->getSecondWordFirstInputIndex(
traverseSession->getProximityInfoState(0));
for (int i = outputWordIndex; i < updatedOutputWordIndex; ++i) {
if (outputSecondWordFirstLetterInputIndex) {
outputIndicesToPartialCommit[i] = secondWordFirstInputIndex;
} else {
outputIndicesToPartialCommit[i] = NOT_AN_INDEX;
}
}
outputWordIndex = updatedOutputWordIndex;
} }
DicNode::managedDelete(terminalDicNode); DicNode::managedDelete(terminalDicNode);
} }

View File

@ -55,7 +55,7 @@ class Suggest : public SuggestInterface {
void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode, void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode,
const bool spaceSubstitution) const; const bool spaceSubstitution) const;
int outputSuggestions(DicTraverseSession *traverseSession, int *frequencies, int outputSuggestions(DicTraverseSession *traverseSession, int *frequencies,
int *outputCodePoints, int *outputIndices, int *outputTypes) const; int *outputCodePoints, int *outputIndicesToPartialCommit, int *outputTypes) const;
void initializeSearch(DicTraverseSession *traverseSession, int commitPoint) const; void initializeSearch(DicTraverseSession *traverseSession, int commitPoint) 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;