am bff2d14d: am 74730a46: Merge "Create the wiring for auto-commit confidence computation."

* commit 'bff2d14d1caf4d70f8c1fdcbbf8e9b41209a3e94':
  Create the wiring for auto-commit confidence computation.
main
Jean Chalard 2013-10-09 17:53:32 -07:00 committed by Android Git Automerger
commit 645d992786
8 changed files with 38 additions and 13 deletions

View File

@ -62,7 +62,8 @@ public final class BinaryDictionary extends Dictionary {
private final int[] mSpaceIndices = new int[MAX_RESULTS]; private final int[] mSpaceIndices = new int[MAX_RESULTS];
private final int[] mOutputScores = new int[MAX_RESULTS]; private final int[] mOutputScores = new int[MAX_RESULTS];
private final int[] mOutputTypes = new int[MAX_RESULTS]; private final int[] mOutputTypes = new int[MAX_RESULTS];
private final int[] mOutputAutoCommitFirstWordConfidence = new int[MAX_RESULTS]; // Only one result is ever used
private final int[] mOutputAutoCommitFirstWordConfidence = new int[1];
private final NativeSuggestOptions mNativeSuggestOptions = new NativeSuggestOptions(); private final NativeSuggestOptions mNativeSuggestOptions = new NativeSuggestOptions();

View File

@ -142,7 +142,7 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
jintArray inputCodePointsArray, jint inputSize, jint commitPoint, jintArray suggestOptions, jintArray inputCodePointsArray, jint inputSize, jint commitPoint, jintArray suggestOptions,
jintArray prevWordCodePointsForBigrams, jintArray outputCodePointsArray, jintArray prevWordCodePointsForBigrams, jintArray outputCodePointsArray,
jintArray scoresArray, jintArray spaceIndicesArray, jintArray outputTypesArray, jintArray scoresArray, jintArray spaceIndicesArray, jintArray outputTypesArray,
jintArray outputAutoCommitFirstWordConfidence) { jintArray outputAutoCommitFirstWordConfidenceArray) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict); Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return 0; if (!dictionary) return 0;
ProximityInfo *pInfo = reinterpret_cast<ProximityInfo *>(proximityInfo); ProximityInfo *pInfo = reinterpret_cast<ProximityInfo *>(proximityInfo);
@ -196,17 +196,23 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
int spaceIndices[spaceIndicesLength]; int spaceIndices[spaceIndicesLength];
const jsize outputTypesLength = env->GetArrayLength(outputTypesArray); const jsize outputTypesLength = env->GetArrayLength(outputTypesArray);
int outputTypes[outputTypesLength]; int outputTypes[outputTypesLength];
const jsize outputAutoCommitFirstWordConfidenceLength =
env->GetArrayLength(outputAutoCommitFirstWordConfidenceArray);
// We only use the first result, as obviously we will only ever autocommit the first one
ASSERT(outputAutoCommitFirstWordConfidenceLength == 1);
int outputAutoCommitFirstWordConfidence[outputAutoCommitFirstWordConfidenceLength];
memset(outputCodePoints, 0, sizeof(outputCodePoints)); memset(outputCodePoints, 0, sizeof(outputCodePoints));
memset(scores, 0, sizeof(scores)); memset(scores, 0, sizeof(scores));
memset(spaceIndices, 0, sizeof(spaceIndices)); memset(spaceIndices, 0, sizeof(spaceIndices));
memset(outputTypes, 0, sizeof(outputTypes)); memset(outputTypes, 0, sizeof(outputTypes));
memset(outputAutoCommitFirstWordConfidence, 0, sizeof(outputAutoCommitFirstWordConfidence));
int count; int count;
if (givenSuggestOptions.isGesture() || inputSize > 0) { if (givenSuggestOptions.isGesture() || inputSize > 0) {
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, commitPoint, &givenSuggestOptions, outputCodePoints,
scores, spaceIndices, outputTypes); scores, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
} else { } else {
count = dictionary->getBigrams(prevWordCodePoints, prevWordCodePointsLength, count = dictionary->getBigrams(prevWordCodePoints, prevWordCodePointsLength,
outputCodePoints, scores, outputTypes); outputCodePoints, scores, outputTypes);
@ -217,6 +223,8 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, j
env->SetIntArrayRegion(scoresArray, 0, scoresLength, scores); env->SetIntArrayRegion(scoresArray, 0, scoresLength, scores);
env->SetIntArrayRegion(spaceIndicesArray, 0, spaceIndicesLength, spaceIndices); env->SetIntArrayRegion(spaceIndicesArray, 0, spaceIndicesLength, spaceIndices);
env->SetIntArrayRegion(outputTypesArray, 0, outputTypesLength, outputTypes); env->SetIntArrayRegion(outputTypesArray, 0, outputTypesLength, outputTypes);
env->SetIntArrayRegion(outputAutoCommitFirstWordConfidenceArray, 0,
outputAutoCommitFirstWordConfidenceLength, outputAutoCommitFirstWordConfidence);
return count; return count;
} }

View File

@ -298,6 +298,9 @@ static inline void prof_out(void) {
#define NOT_AN_INDEX (-1) #define NOT_AN_INDEX (-1)
#define NOT_A_PROBABILITY (-1) #define NOT_A_PROBABILITY (-1)
#define NOT_A_DICT_POS (S_INT_MIN) #define NOT_A_DICT_POS (S_INT_MIN)
// A special value to mean the first word confidence makes no sense in this case,
// e.g. this is not a multi-word suggestion.
#define NOT_A_FIRST_WORD_CONFIDENCE (S_INT_MIN)
#define KEYCODE_SPACE ' ' #define KEYCODE_SPACE ' '
#define KEYCODE_SINGLE_QUOTE '\'' #define KEYCODE_SINGLE_QUOTE '\''

View File

@ -55,14 +55,14 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
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, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies, const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
int *spaceIndices, int *outputTypes) const { int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
int result = 0; int result = 0;
if (suggestOptions->isGesture()) { if (suggestOptions->isGesture()) {
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, commitPoint, outWords,
frequencies, spaceIndices, outputTypes); frequencies, spaceIndices, outputTypes, outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) { if (DEBUG_DICT) {
DUMP_RESULT(outWords, frequencies); DUMP_RESULT(outWords, frequencies);
} }
@ -72,7 +72,8 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
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, commitPoint,
outWords, frequencies, spaceIndices, outputTypes); outWords, frequencies, spaceIndices, outputTypes,
outputAutoCommitFirstWordConfidence);
if (DEBUG_DICT) { if (DEBUG_DICT) {
DUMP_RESULT(outWords, frequencies); DUMP_RESULT(outWords, frequencies);
} }

View File

@ -60,7 +60,7 @@ class Dictionary {
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, int commitPoint,
const SuggestOptions *const suggestOptions, int *outWords, int *frequencies, const SuggestOptions *const suggestOptions, int *outWords, int *frequencies,
int *spaceIndices, int *outputTypes) const; int *spaceIndices, int *outputTypes, int *outputAutoCommitFirstWordConfidence) const;
int getBigrams(const int *word, int length, int *outWords, int *frequencies, int getBigrams(const int *word, int length, int *outWords, int *frequencies,
int *outputTypes) const; int *outputTypes) const;

View File

@ -49,7 +49,7 @@ const float Suggest::AUTOCORRECT_CLASSIFICATION_THRESHOLD = 0.33f;
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 *frequencies, int *outputIndices, int inputSize, int commitPoint, int *outWords, int *frequencies, int *outputIndices,
int *outputTypes) const { int *outputTypes, int *outputAutoCommitFirstWordConfidence) const {
PROF_OPEN; PROF_OPEN;
PROF_START(0); PROF_START(0);
const float maxSpatialDistance = TRAVERSAL->getMaxSpatialDistance(); const float maxSpatialDistance = TRAVERSAL->getMaxSpatialDistance();
@ -70,7 +70,8 @@ int Suggest::getSuggestions(ProximityInfo *pInfo, void *traverseSession,
} }
PROF_END(1); PROF_END(1);
PROF_START(2); PROF_START(2);
const int size = outputSuggestions(tSession, frequencies, outWords, outputIndices, outputTypes); const int size = outputSuggestions(tSession, frequencies, outWords, outputIndices, outputTypes,
outputAutoCommitFirstWordConfidence);
PROF_END(2); PROF_END(2);
PROF_CLOSE; PROF_CLOSE;
return size; return size;
@ -117,7 +118,8 @@ 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 *outputIndicesToPartialCommit, int *outputTypes) const { int *outputCodePoints, int *outputIndicesToPartialCommit, int *outputTypes,
int *outputAutoCommitFirstWordConfidence) const {
#if DEBUG_EVALUATE_MOST_PROBABLE_STRING #if DEBUG_EVALUATE_MOST_PROBABLE_STRING
const int terminalSize = 0; const int terminalSize = 0;
#else #else
@ -164,6 +166,8 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
// TODO: have partial commit work even with multiple pointers. // TODO: have partial commit work even with multiple pointers.
const bool outputSecondWordFirstLetterInputIndex = const bool outputSecondWordFirstLetterInputIndex =
traverseSession->isOnlyOnePointerUsed(0 /* pointerId */); traverseSession->isOnlyOnePointerUsed(0 /* pointerId */);
outputAutoCommitFirstWordConfidence[0] = computeFirstWordConfidence();
// 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) {
@ -251,6 +255,11 @@ int Suggest::outputSuggestions(DicTraverseSession *traverseSession, int *frequen
return outputWordIndex; return outputWordIndex;
} }
int Suggest::computeFirstWordConfidence() const {
// TODO: implement this.
return NOT_A_FIRST_WORD_CONFIDENCE;
}
/** /**
* Expands the dicNodes in the current search priority queue by advancing to the possible child * Expands the dicNodes in the current search priority queue by advancing to the possible child
* nodes based on the next touch point(s) (or no touch points for lookahead) * nodes based on the next touch point(s) (or no touch points for lookahead)

View File

@ -48,14 +48,17 @@ class Suggest : public SuggestInterface {
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 commitPoint,
int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const; int *outWords, int *frequencies, int *outputIndices, int *outputTypes,
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;
int outputSuggestions(DicTraverseSession *traverseSession, int *frequencies, int outputSuggestions(DicTraverseSession *traverseSession, int *frequencies,
int *outputCodePoints, int *outputIndicesToPartialCommit, int *outputTypes) const; int *outputCodePoints, int *outputIndicesToPartialCommit, int *outputTypes,
int *outputAutoCommitFirstWordConfidence) const;
int computeFirstWordConfidence() 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;

View File

@ -28,7 +28,7 @@ class SuggestInterface {
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 *frequencies, int *outputIndices, int commitPoint, int *outWords, int *frequencies, int *outputIndices,
int *outputTypes) const = 0; int *outputTypes, int *outputAutoCommitFirstWordConfidence) const = 0;
SuggestInterface() {} SuggestInterface() {}
virtual ~SuggestInterface() {} virtual ~SuggestInterface() {}
private: private: