mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Pass traverse session
Change-Id: I84bfaaa406e3f51421c08a7ee8f9576ebdba54d4
This commit is contained in:
parent
c4e4dfe17d
commit
9127811493
@ -90,9 +90,9 @@ public class BinaryDictionary extends Dictionary {
|
||||
private native void closeNative(long dict);
|
||||
private native int getFrequencyNative(long dict, int[] word, int wordLength);
|
||||
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
|
||||
private native int getSuggestionsNative(long dict, long proximityInfo, int[] xCoordinates,
|
||||
int[] yCoordinates, int[] times, int[] pointerIds, int[] inputCodes, int codesSize,
|
||||
int commitPoint, boolean isGesture,
|
||||
private native int getSuggestionsNative(long dict, long proximityInfo, long traverseSession,
|
||||
int[] xCoordinates, int[] yCoordinates, int[] times, int[] pointerIds,
|
||||
int[] inputCodes, int codesSize, int commitPoint, boolean isGesture,
|
||||
int[] prevWordCodePointArray, boolean useFullEditDistance, char[] outputChars,
|
||||
int[] outputScores, int[] outputIndices, int[] outputTypes);
|
||||
private static native float calcNormalizedScoreNative(
|
||||
@ -129,7 +129,8 @@ public class BinaryDictionary extends Dictionary {
|
||||
final int codesSize = isGesture ? ips.getPointerSize() : composerSize;
|
||||
// proximityInfo and/or prevWordForBigrams may not be null.
|
||||
final int tmpCount = getSuggestionsNative(mNativeDict,
|
||||
proximityInfo.getNativeProximityInfo(), ips.getXCoordinates(),
|
||||
proximityInfo.getNativeProximityInfo(),
|
||||
mDicTraverseSession.getSession(), ips.getXCoordinates(),
|
||||
ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(),
|
||||
mInputCodes, codesSize, 0 /* commitPoint */, isGesture, prevWordCodePointArray,
|
||||
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes);
|
||||
|
@ -30,6 +30,10 @@ public class DicTraverseSession {
|
||||
locale != null ? locale.toString() : "");
|
||||
}
|
||||
|
||||
public long getSession() {
|
||||
return mNativeDicTraverseSession;
|
||||
}
|
||||
|
||||
private native long setDicTraverseSessionNative(String locale);
|
||||
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
|
||||
|
||||
|
@ -122,14 +122,15 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||
}
|
||||
|
||||
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jlong dict,
|
||||
jlong proximityInfo, jintArray xCoordinatesArray, jintArray yCoordinatesArray,
|
||||
jintArray timesArray, jintArray pointerIdArray, jintArray inputArray, jint arraySize,
|
||||
jint commitPoint, jboolean isGesture,
|
||||
jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray,
|
||||
jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdArray,
|
||||
jintArray inputArray, jint arraySize, jint commitPoint, jboolean isGesture,
|
||||
jintArray prevWordForBigrams, jboolean useFullEditDistance, jcharArray outputArray,
|
||||
jintArray frequencyArray, jintArray spaceIndexArray, jintArray outputTypesArray) {
|
||||
Dictionary *dictionary = (Dictionary*) dict;
|
||||
Dictionary *dictionary = reinterpret_cast<Dictionary*>(dict);
|
||||
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 *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, 0);
|
||||
int *times = env->GetIntArrayElements(timesArray, 0);
|
||||
@ -145,10 +146,10 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
|
||||
|
||||
int count;
|
||||
if (isGesture || arraySize > 1) {
|
||||
count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, times, pointerIds,
|
||||
inputCodes, arraySize, prevWordChars, prevWordLength, commitPoint, isGesture,
|
||||
useFullEditDistance, (unsigned short*) outputChars, frequencies, spaceIndices,
|
||||
outputTypes);
|
||||
count = dictionary->getSuggestions(pInfo, traverseSession, xCoordinates, yCoordinates,
|
||||
times, pointerIds, inputCodes, arraySize, prevWordChars, prevWordLength,
|
||||
commitPoint, isGesture, useFullEditDistance, (unsigned short*) outputChars,
|
||||
frequencies, spaceIndices, outputTypes);
|
||||
} else {
|
||||
count = dictionary->getBigrams(prevWordChars, prevWordLength, inputCodes,
|
||||
arraySize, (unsigned short*) outputChars, frequencies, outputTypes);
|
||||
@ -247,7 +248,7 @@ void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
|
||||
static JNINativeMethod sMethods[] = {
|
||||
{"openNative", "(Ljava/lang/String;JJIIIII)J", (void*)latinime_BinaryDictionary_open},
|
||||
{"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},
|
||||
{"getFrequencyNative", "(J[II)I", (void*)latinime_BinaryDictionary_getFrequency},
|
||||
{"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram},
|
||||
|
@ -26,12 +26,13 @@ void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
|
||||
|
||||
static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
|
||||
jstring localejStr) {
|
||||
void *session = DicTraverseWrapper::getDicTraverseSession();
|
||||
return reinterpret_cast<jlong>(session);
|
||||
void *traverseSession = DicTraverseWrapper::getDicTraverseSession();
|
||||
return reinterpret_cast<jlong>(traverseSession);
|
||||
}
|
||||
|
||||
static void latinime_DicTraverseSession_release(JNIEnv *env, jobject object, jlong session) {
|
||||
void *pi = reinterpret_cast<void*>(session);
|
||||
static void latinime_DicTraverseSession_release(
|
||||
JNIEnv *env, jobject object, jlong traverseSession) {
|
||||
void *pi = reinterpret_cast<void*>(traverseSession);
|
||||
if (!pi) return;
|
||||
DicTraverseWrapper::releaseDicTraverseSession(pi);
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ class DicTraverseWrapper {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static void releaseDicTraverseSession(void *session) {
|
||||
static void releaseDicTraverseSession(void *traverseSession) {
|
||||
if (sDicTraverseSessionReleaseMethod) {
|
||||
sDicTraverseSessionReleaseMethod(session);
|
||||
sDicTraverseSessionReleaseMethod(traverseSession);
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
@ -56,16 +56,17 @@ Dictionary::~Dictionary() {
|
||||
delete mGestureDecoder;
|
||||
}
|
||||
|
||||
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars,
|
||||
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession,
|
||||
int *xcoordinates, int *ycoordinates, int *times, int *pointerIds,
|
||||
int *codes, int codesSize, int *prevWordChars,
|
||||
int prevWordLength, int commitPoint, bool isGesture,
|
||||
bool useFullEditDistance, unsigned short *outWords,
|
||||
int *frequencies, int *spaceIndices, int *outputTypes) {
|
||||
int result = 0;
|
||||
if (isGesture) {
|
||||
mGestureDecoder->setPrevWord(prevWordChars, prevWordLength);
|
||||
result = mGestureDecoder->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
|
||||
times, pointerIds, codes, codesSize, commitPoint,
|
||||
result = mGestureDecoder->getSuggestions(proximityInfo, traverseSession,
|
||||
xcoordinates, ycoordinates, times, pointerIds, codes, codesSize, commitPoint,
|
||||
outWords, frequencies, spaceIndices, outputTypes);
|
||||
if (DEBUG_DICT) {
|
||||
DUMP_RESULT(outWords, frequencies, 18 /* MAX_WORDS */, MAX_WORD_LENGTH_INTERNAL);
|
||||
|
@ -44,9 +44,9 @@ class Dictionary {
|
||||
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
|
||||
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions);
|
||||
|
||||
int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
|
||||
int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars,
|
||||
int prevWordLength, int commitPoint, bool isGesture,
|
||||
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
||||
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
|
||||
int *prevWordChars, int prevWordLength, int commitPoint, bool isGesture,
|
||||
bool useFullEditDistance, unsigned short *outWords,
|
||||
int *frequencies, int *spaceIndices, int *outputTypes);
|
||||
|
||||
|
@ -37,15 +37,15 @@ class GestureDecoderWrapper : public IncrementalDecoderInterface {
|
||||
delete mIncrementalDecoderInterface;
|
||||
}
|
||||
|
||||
int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times,
|
||||
int *pointerIds, int *codes, int inputSize, int commitPoint,
|
||||
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
||||
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
|
||||
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
|
||||
if (!mIncrementalDecoderInterface) {
|
||||
return 0;
|
||||
}
|
||||
return mIncrementalDecoderInterface->getSuggestions(
|
||||
pInfo, inputXs, inputYs, times, pointerIds, codes, inputSize, commitPoint,
|
||||
outWords, frequencies, outputIndices, outputTypes);
|
||||
pInfo, traverseSession, inputXs, inputYs, times, pointerIds, codes,
|
||||
inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
@ -28,9 +28,10 @@ class ProximityInfo;
|
||||
|
||||
class IncrementalDecoderInterface {
|
||||
public:
|
||||
virtual int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times,
|
||||
int *pointerIds, int *codes, int inputSize, int commitPoint,
|
||||
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) = 0;
|
||||
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession,
|
||||
int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes,
|
||||
int inputSize, int commitPoint, unsigned short *outWords, int *frequencies,
|
||||
int *outputIndices, int *outputTypes) = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram,
|
||||
const uint8_t *dictRoot, int rootPos) = 0;
|
||||
|
@ -37,15 +37,15 @@ class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
|
||||
delete mIncrementalDecoderInterface;
|
||||
}
|
||||
|
||||
int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times,
|
||||
int *pointerIds, int *codes, int inputSize, int commitPoint,
|
||||
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
|
||||
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
|
||||
unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
|
||||
if (!mIncrementalDecoderInterface) {
|
||||
return 0;
|
||||
}
|
||||
return mIncrementalDecoderInterface->getSuggestions(
|
||||
pInfo, inputXs, inputYs, times, pointerIds, codes, inputSize, commitPoint,
|
||||
outWords, frequencies, outputIndices, outputTypes);
|
||||
pInfo, traverseSession, inputXs, inputYs, times, pointerIds, codes,
|
||||
inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
Loading…
Reference in New Issue
Block a user