Pass traverse session

Change-Id: I84bfaaa406e3f51421c08a7ee8f9576ebdba54d4
main
Satoshi Kataoka 2012-08-08 21:23:25 +09:00
parent c4e4dfe17d
commit 9127811493
10 changed files with 47 additions and 38 deletions

View File

@ -90,9 +90,9 @@ public class BinaryDictionary extends Dictionary {
private native void closeNative(long dict); private native void closeNative(long dict);
private native int getFrequencyNative(long dict, int[] word, int wordLength); private native int getFrequencyNative(long dict, int[] word, int wordLength);
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2); private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates, private native int getSuggestionsNative(long dict, long proximityInfo, long traverseSession,
int[] yCoordinates, int[] times, int[] pointerIds, int[] inputCodes, int codesSize, int[] xCoordinates, int[] yCoordinates, int[] times, int[] pointerIds,
int commitPoint, boolean isGesture, int[] inputCodes, int codesSize, int commitPoint, boolean isGesture,
int[] prevWordCodePointArray, boolean useFullEditDistance, char[] outputChars, int[] prevWordCodePointArray, boolean useFullEditDistance, char[] outputChars,
int[] outputScores, int[] outputIndices, int[] outputTypes); int[] outputScores, int[] outputIndices, int[] outputTypes);
private static native float calcNormalizedScoreNative( private static native float calcNormalizedScoreNative(
@ -129,7 +129,8 @@ public class BinaryDictionary extends Dictionary {
final int codesSize = isGesture ? ips.getPointerSize() : composerSize; final int codesSize = isGesture ? ips.getPointerSize() : composerSize;
// proximityInfo and/or prevWordForBigrams may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
final int tmpCount = getSuggestionsNative(mNativeDict, final int tmpCount = getSuggestionsNative(mNativeDict,
proximityInfo.getNativeProximityInfo(), ips.getXCoordinates(), proximityInfo.getNativeProximityInfo(),
mDicTraverseSession.getSession(), ips.getXCoordinates(),
ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
mInputCodes, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray, mInputCodes, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray,
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes); mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes);

View File

@ -30,6 +30,10 @@ public class DicTraverseSession {
locale != null ? locale.toString() : ""); locale != null ? locale.toString() : "");
} }
public long getSession() {
return mNativeDicTraverseSession;
}
private native long setDicTraverseSessionNative(String locale); private native long setDicTraverseSessionNative(String locale);
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession); private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);

View File

@ -122,14 +122,15 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
} }
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jlong dict, static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jlong dict,
jlong proximityInfo, jintArray xCoordinatesArray, jintArray yCoordinatesArray, jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray,
jintArray timesArray, jintArray pointerIdArray, jintArray inputArray, jint arraySize, jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdArray,
jint commitPoint, jboolean isGesture, jintArray inputArray, jint arraySize, jint commitPoint, jboolean isGesture,
jintArray prevWordForBigrams, jboolean useFullEditDistance, jcharArray outputArray, jintArray prevWordForBigrams, jboolean useFullEditDistance, jcharArray outputArray,
jintArray frequencyArray, jintArray spaceIndexArray, jintArray outputTypesArray) { jintArray frequencyArray, jintArray spaceIndexArray, jintArray outputTypesArray) {
Dictionary *dictionary = (Dictionary*) dict; Dictionary *dictionary = reinterpret_cast<Dictionary*>(dict);
if (!dictionary) return 0; if (!dictionary) return 0;
ProximityInfo *pInfo = (ProximityInfo*)proximityInfo; ProximityInfo *pInfo = reinterpret_cast<ProximityInfo*>(proximityInfo);
void *traverseSession = reinterpret_cast<void*>(dicTraverseSession);
int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, 0); int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, 0);
int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, 0); int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, 0);
int *times = env->GetIntArrayElements(timesArray, 0); int *times = env->GetIntArrayElements(timesArray, 0);
@ -145,10 +146,10 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
int count; int count;
if (isGesture || arraySize > 1) { if (isGesture || arraySize > 1) {
count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, times, pointerIds, count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
inputCodes, arraySize, prevWordChars, prevWordLength, commitPoint, isGesture, times, pointerIds, inputCodes, arraySize, prevWordChars, prevWordLength,
useFullEditDistance, (unsigned short*) outputChars, frequencies, spaceIndices, commitPoint, isGesture, useFullEditDistance, (unsigned short*) outputChars,
outputTypes); frequencies, spaceIndices, outputTypes);
} else { } else {
count = dictionary->getBigrams(prevWordChars, prevWordLength, inputCodes, count = dictionary->getBigrams(prevWordChars, prevWordLength, inputCodes,
arraySize, (unsigned short*) outputChars, frequencies, outputTypes); arraySize, (unsigned short*) outputChars, frequencies, outputTypes);
@ -247,7 +248,7 @@ void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = {
{"openNative", "(Ljava/lang/String;JJIIIII)J", (void*)latinime_BinaryDictionary_open}, {"openNative", "(Ljava/lang/String;JJIIIII)J", (void*)latinime_BinaryDictionary_open},
{"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close}, {"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close},
{"getSuggestionsNative", "(JJ[I[I[I[I[IIIZ[IZ[C[I[I[I)I", {"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[C[I[I[I)I",
(void*) latinime_BinaryDictionary_getSuggestions}, (void*) latinime_BinaryDictionary_getSuggestions},
{"getFrequencyNative", "(J[II)I", (void*)latinime_BinaryDictionary_getFrequency}, {"getFrequencyNative", "(J[II)I", (void*)latinime_BinaryDictionary_getFrequency},
{"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram}, {"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram},

View File

@ -26,12 +26,13 @@ void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object, static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
jstring localejStr) { jstring localejStr) {
void *session = DicTraverseWrapper::getDicTraverseSession(); void *traverseSession = DicTraverseWrapper::getDicTraverseSession();
return reinterpret_cast<jlong>(session); return reinterpret_cast<jlong>(traverseSession);
} }
static void latinime_DicTraverseSession_release(JNIEnv *env, jobject object, jlong session) { static void latinime_DicTraverseSession_release(
void *pi = reinterpret_cast<void*>(session); JNIEnv *env, jobject object, jlong traverseSession) {
void *pi = reinterpret_cast<void*>(traverseSession);
if (!pi) return; if (!pi) return;
DicTraverseWrapper::releaseDicTraverseSession(pi); DicTraverseWrapper::releaseDicTraverseSession(pi);
} }

View File

@ -31,9 +31,9 @@ class DicTraverseWrapper {
} }
return 0; return 0;
} }
static void releaseDicTraverseSession(void *session) { static void releaseDicTraverseSession(void *traverseSession) {
if (sDicTraverseSessionReleaseMethod) { if (sDicTraverseSessionReleaseMethod) {
sDicTraverseSessionReleaseMethod(session); sDicTraverseSessionReleaseMethod(traverseSession);
} }
} }
private: private:

View File

@ -56,16 +56,17 @@ Dictionary::~Dictionary() {
delete mGestureDecoder; delete mGestureDecoder;
} }
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates, int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession,
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars, int *xcoordinates, int *ycoordinates, int *times, int *pointerIds,
int *codes, int codesSize, int *prevWordChars,
int prevWordLength, int commitPoint, bool isGesture, int prevWordLength, int commitPoint, bool isGesture,
bool useFullEditDistance, unsigned short *outWords, bool useFullEditDistance, unsigned short *outWords,
int *frequencies, int *spaceIndices, int *outputTypes) { int *frequencies, int *spaceIndices, int *outputTypes) {
int result = 0; int result = 0;
if (isGesture) { if (isGesture) {
mGestureDecoder->setPrevWord(prevWordChars, prevWordLength); mGestureDecoder->setPrevWord(prevWordChars, prevWordLength);
result = mGestureDecoder->getSuggestions(proximityInfo, xcoordinates, ycoordinates, result = mGestureDecoder->getSuggestions(proximityInfo, traverseSession,
times, pointerIds, codes, codesSize, commitPoint, xcoordinates, ycoordinates, times, pointerIds, codes, codesSize, commitPoint,
outWords, frequencies, spaceIndices, outputTypes); outWords, frequencies, spaceIndices, outputTypes);
if (DEBUG_DICT) { if (DEBUG_DICT) {
DUMP_RESULT(outWords, frequencies, 18 /* MAX_WORDS */, MAX_WORD_LENGTH_INTERNAL); DUMP_RESULT(outWords, frequencies, 18 /* MAX_WORDS */, MAX_WORD_LENGTH_INTERNAL);

View File

@ -44,9 +44,9 @@ class Dictionary {
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler, Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions); int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions);
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates, int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars, int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
int prevWordLength, int commitPoint, bool isGesture, int *prevWordChars, int prevWordLength, int commitPoint, bool isGesture,
bool useFullEditDistance, unsigned short *outWords, bool useFullEditDistance, unsigned short *outWords,
int *frequencies, int *spaceIndices, int *outputTypes); int *frequencies, int *spaceIndices, int *outputTypes);

View File

@ -37,15 +37,15 @@ class GestureDecoderWrapper : public IncrementalDecoderInterface {
delete mIncrementalDecoderInterface; delete mIncrementalDecoderInterface;
} }
int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times, int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *pointerIds, int *codes, int inputSize, int commitPoint, int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) { unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
if (!mIncrementalDecoderInterface) { if (!mIncrementalDecoderInterface) {
return 0; return 0;
} }
return mIncrementalDecoderInterface->getSuggestions( return mIncrementalDecoderInterface->getSuggestions(
pInfo, inputXs, inputYs, times, pointerIds, codes, inputSize, commitPoint, pInfo, traverseSession, inputXs, inputYs, times, pointerIds, codes,
outWords, frequencies, outputIndices, outputTypes); inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
} }
void reset() { void reset() {

View File

@ -28,9 +28,10 @@ class ProximityInfo;
class IncrementalDecoderInterface { class IncrementalDecoderInterface {
public: public:
virtual int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times, virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession,
int *pointerIds, int *codes, int inputSize, int commitPoint, int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes,
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) = 0; int inputSize, int commitPoint, unsigned short *outWords, int *frequencies,
int *outputIndices, int *outputTypes) = 0;
virtual void reset() = 0; virtual void reset() = 0;
virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram, virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
const uint8_t *dictRoot, int rootPos) = 0; const uint8_t *dictRoot, int rootPos) = 0;

View File

@ -37,15 +37,15 @@ class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
delete mIncrementalDecoderInterface; delete mIncrementalDecoderInterface;
} }
int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times, int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *pointerIds, int *codes, int inputSize, int commitPoint, int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) { unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
if (!mIncrementalDecoderInterface) { if (!mIncrementalDecoderInterface) {
return 0; return 0;
} }
return mIncrementalDecoderInterface->getSuggestions( return mIncrementalDecoderInterface->getSuggestions(
pInfo, inputXs, inputYs, times, pointerIds, codes, inputSize, commitPoint, pInfo, traverseSession, inputXs, inputYs, times, pointerIds, codes,
outWords, frequencies, outputIndices, outputTypes); inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
} }
void reset() { void reset() {