diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/jni/Android.mk | 3 | ||||
-rw-r--r-- | native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp | 25 | ||||
-rw-r--r-- | native/jni/src/dictionary.cpp | 2 | ||||
-rw-r--r-- | native/jni/src/dictionary.h | 31 | ||||
-rw-r--r-- | native/jni/src/gesture/build_check.cpp | 21 | ||||
-rw-r--r-- | native/jni/src/gesture/gesture_decoder.h | 37 | ||||
-rw-r--r-- | native/jni/src/gesture/gesture_decoder_impl.h | 43 | ||||
-rw-r--r-- | native/jni/src/gesture/incremental_decoder.h | 37 | ||||
-rw-r--r-- | native/jni/src/gesture/incremental_decoder_impl.h | 40 | ||||
-rw-r--r-- | native/jni/src/gesture/incremental_decoder_interface.h | 40 |
10 files changed, 261 insertions, 18 deletions
diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 3bb7b58f1..5d705b1ff 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -47,7 +47,8 @@ LATIN_IME_CORE_SRC_FILES := \ dictionary.cpp \ proximity_info.cpp \ proximity_info_state.cpp \ - unigram_dictionary.cpp + unigram_dictionary.cpp \ + gesture/build_check.cpp LOCAL_SRC_FILES := \ $(LATIN_IME_JNI_SRC_FILES) \ diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index d10dc962e..3fa45da55 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -128,28 +128,37 @@ 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 inputArray, jint arraySize, jintArray prevWordForBigrams, - jboolean useFullEditDistance, jcharArray outputArray, jintArray frequencyArray) { - Dictionary *dictionary = (Dictionary*)dict; + jintArray timesArray, jintArray pointerIdArray, jintArray inputArray, jint arraySize, + jint commitPoint, jboolean isGesture, jint dicTypeId, + jintArray prevWordForBigrams, jboolean useFullEditDistance, jcharArray outputArray, + jintArray frequencyArray, jintArray spaceIndexArray) { + Dictionary *dictionary = (Dictionary*) dict; if (!dictionary) return 0; ProximityInfo *pInfo = (ProximityInfo*)proximityInfo; int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, 0); int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, 0); + int *times = env->GetIntArrayElements(timesArray, 0); + int *pointerIds = env->GetIntArrayElements(pointerIdArray, 0); int *frequencies = env->GetIntArrayElements(frequencyArray, 0); int *inputCodes = env->GetIntArrayElements(inputArray, 0); jchar *outputChars = env->GetCharArrayElements(outputArray, 0); + int *spaceIndices = env->GetIntArrayElements(spaceIndexArray, 0); jint *prevWordChars = prevWordForBigrams ? env->GetIntArrayElements(prevWordForBigrams, 0) : 0; jsize prevWordLength = prevWordChars ? env->GetArrayLength(prevWordForBigrams) : 0; - int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes, - arraySize, prevWordChars, prevWordLength, useFullEditDistance, - (unsigned short*) outputChars, frequencies); + int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, times, pointerIds, + inputCodes, arraySize, prevWordChars, prevWordLength, commitPoint, isGesture, + dicTypeId, useFullEditDistance, (unsigned short*) outputChars, + frequencies, spaceIndices); if (prevWordChars) { env->ReleaseIntArrayElements(prevWordForBigrams, prevWordChars, JNI_ABORT); } + env->ReleaseIntArrayElements(spaceIndexArray, spaceIndices, 0); env->ReleaseCharArrayElements(outputArray, outputChars, 0); env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT); env->ReleaseIntArrayElements(frequencyArray, frequencies, 0); + env->ReleaseIntArrayElements(pointerIdArray, pointerIds, 0); + env->ReleaseIntArrayElements(timesArray, times, 0); env->ReleaseIntArrayElements(yCoordinatesArray, yCoordinates, 0); env->ReleaseIntArrayElements(xCoordinatesArray, xCoordinates, 0); return count; @@ -251,8 +260,8 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) { static JNINativeMethod sMethods[] = { {"openNative", "(Ljava/lang/String;JJIIII)J", (void*)latinime_BinaryDictionary_open}, {"closeNative", "(J)V", (void*)latinime_BinaryDictionary_close}, - {"getSuggestionsNative", "(JJ[I[I[II[IZ[C[I)I", - (void*)latinime_BinaryDictionary_getSuggestions}, + {"getSuggestionsNative", "(JJ[I[I[I[I[IIIZI[IZ[C[I[I)I", + (void*) latinime_BinaryDictionary_getSuggestions}, {"getFrequencyNative", "(J[II)I", (void*)latinime_BinaryDictionary_getFrequency}, {"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram}, {"getBigramsNative", "(J[II[II[C[III)I", (void*)latinime_BinaryDictionary_getBigrams}, diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp index 83bb26731..e0b7f87b2 100644 --- a/native/jni/src/dictionary.cpp +++ b/native/jni/src/dictionary.cpp @@ -43,6 +43,8 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, mUnigramDictionary = new UnigramDictionary(mDict + headerSize, typedLetterMultiplier, fullWordMultiplier, maxWordLength, maxWords, options); mBigramDictionary = new BigramDictionary(mDict + headerSize, maxWordLength); + mGestureDecoder = new GestureDecoder(maxWordLength, maxWords); + mGestureDecoder->setDict(mUnigramDictionary, mBigramDictionary); } Dictionary::~Dictionary() { diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h index fd69f79e3..708cb0909 100644 --- a/native/jni/src/dictionary.h +++ b/native/jni/src/dictionary.h @@ -22,6 +22,7 @@ #include "bigram_dictionary.h" #include "char_utils.h" #include "defines.h" +#include "gesture/gesture_decoder.h" #include "proximity_info.h" #include "unigram_dictionary.h" #include "words_priority_queue_pool.h" @@ -34,15 +35,26 @@ class Dictionary { int fullWordMultiplier, int maxWordLength, int maxWords); int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates, - int *codes, int codesSize, const int32_t* prevWordChars, const int prevWordLength, - bool useFullEditDistance, unsigned short *outWords, int *frequencies) const { - std::map<int, int> bigramMap; - uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE]; - mBigramDictionary->fillBigramAddressToFrequencyMapAndFilter(prevWordChars, - prevWordLength, &bigramMap, bigramFilter); - return mUnigramDictionary->getSuggestions(proximityInfo, - xcoordinates, ycoordinates, codes, codesSize, &bigramMap, - bigramFilter, useFullEditDistance, outWords, frequencies); + int *times, int *pointerIds, int *codes, int codesSize, int *prevWordChars, + int prevWordLength, int commitPoint, bool isGesture, int dicTypeId, + bool useFullEditDistance, unsigned short *outWords, + int *frequencies, int *spaceIndices) { + int result = 0; + if (isGesture) { + mGestureDecoder->setPrevWord(prevWordChars, prevWordLength); + result = mGestureDecoder->getSuggestions(proximityInfo, xcoordinates, ycoordinates, + times, pointerIds, codes, codesSize, commitPoint, dicTypeId == 1 /* main */, + outWords, frequencies, spaceIndices); + } else { + std::map<int, int> bigramMap; + uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE]; + mBigramDictionary->fillBigramAddressToFrequencyMapAndFilter(prevWordChars, + prevWordLength, &bigramMap, bigramFilter); + result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, + ycoordinates, codes, codesSize, &bigramMap, bigramFilter, + useFullEditDistance, outWords, frequencies); + } + return result; } int getBigrams(const int32_t *word, int length, int *codes, int codesSize, @@ -75,6 +87,7 @@ class Dictionary { const UnigramDictionary *mUnigramDictionary; const BigramDictionary *mBigramDictionary; + GestureDecoder *mGestureDecoder; }; // public static utility methods diff --git a/native/jni/src/gesture/build_check.cpp b/native/jni/src/gesture/build_check.cpp new file mode 100644 index 000000000..8ec94f593 --- /dev/null +++ b/native/jni/src/gesture/build_check.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gesture_decoder.h" + +namespace latinime { +}; +// namespace latinime diff --git a/native/jni/src/gesture/gesture_decoder.h b/native/jni/src/gesture/gesture_decoder.h new file mode 100644 index 000000000..8e79555bd --- /dev/null +++ b/native/jni/src/gesture/gesture_decoder.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_GESTURE_DECODER_H +#define LATINIME_GESTURE_DECODER_H + +#include "defines.h" +#include "gesture_decoder_impl.h" + +namespace latinime { + +class GestureDecoder : public GestureDecoderImpl { + + public: + GestureDecoder(int maxWordLength, int maxWords) : + GestureDecoderImpl(maxWordLength, maxWords) { + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(GestureDecoder); +}; +} // namespace latinime + +#endif // LATINIME_INCREMENTAL_DECODER_H diff --git a/native/jni/src/gesture/gesture_decoder_impl.h b/native/jni/src/gesture/gesture_decoder_impl.h new file mode 100644 index 000000000..be4e8b3c2 --- /dev/null +++ b/native/jni/src/gesture/gesture_decoder_impl.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_GESTURE_DECODER_IMPL_H +#define LATINIME_GESTURE_DECODER_IMPL_H + +#include "defines.h" +#include "incremental_decoder.h" + +namespace latinime { + +class GestureDecoderImpl : public IncrementalDecoder { + + public: + GestureDecoderImpl(int maxWordLength, int maxWords) : + IncrementalDecoder(maxWordLength, maxWords) { + } + + int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times, + int *pointerIds, int *codes, int inputSize, int commitPoint, bool isMainDict, + unsigned short *outWords, int *frequencies, int *outputIndices) { + return 0; + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(GestureDecoderImpl); +}; +} // namespace latinime + +#endif // LATINIME_GESTURE_DECODER_IMPL_H diff --git a/native/jni/src/gesture/incremental_decoder.h b/native/jni/src/gesture/incremental_decoder.h new file mode 100644 index 000000000..fe935529f --- /dev/null +++ b/native/jni/src/gesture/incremental_decoder.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_INCREMENTAL_DECODER_H +#define LATINIME_INCREMENTAL_DECODER_H + +#include "defines.h" +#include "incremental_decoder_impl.h" + +namespace latinime { + +class IncrementalDecoder : public IncrementalDecoderImpl { + + public: + IncrementalDecoder(int maxWordLength, int maxWords) : + IncrementalDecoderImpl(maxWordLength, maxWords) { + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalDecoder); +}; +} // namespace latinime + +#endif // LATINIME_INCREMENTAL_DECODER_H diff --git a/native/jni/src/gesture/incremental_decoder_impl.h b/native/jni/src/gesture/incremental_decoder_impl.h new file mode 100644 index 000000000..5731ad892 --- /dev/null +++ b/native/jni/src/gesture/incremental_decoder_impl.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_INCREMENTAL_DECODER_IMPL_H +#define LATINIME_INCREMENTAL_DECODER_IMPL_H + +#include "bigram_dictionary.h" +#include "defines.h" +#include "incremental_decoder_interface.h" +#include "unigram_dictionary.h" + +namespace latinime { + +class IncrementalDecoderImpl : IncrementalDecoderInterface { + + public: + IncrementalDecoderImpl(int maxWordLength, int maxWords) { }; + void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram) { }; + void setPrevWord(const int32_t *prevWord, int prevWordLength) { }; + void reset() { }; + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalDecoderImpl); +}; +} // namespace latinime + +#endif // LATINIME_INCREMENTAL_DECODER_IMPL_H diff --git a/native/jni/src/gesture/incremental_decoder_interface.h b/native/jni/src/gesture/incremental_decoder_interface.h new file mode 100644 index 000000000..d34b0da11 --- /dev/null +++ b/native/jni/src/gesture/incremental_decoder_interface.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_INCREMENTAL_DECODER_INTERFACE_H +#define LATINIME_INCREMENTAL_DECODER_INTERFACE_H + +#include "bigram_dictionary.h" +#include "defines.h" +#include "proximity_info.h" +#include "unigram_dictionary.h" + +namespace latinime { + +class IncrementalDecoderInterface { + + public: + virtual int getSuggestions(ProximityInfo *pInfo, int *inputXs, int *inputYs, int *times, + int *pointerIds, int *codes, int inputSize, int commitPoint, bool isMainDict, + unsigned short *outWords, int *frequencies, int *outputIndices) = 0; + virtual void reset() = 0; + virtual void setDict(const UnigramDictionary *dict, const BigramDictionary *bigram) = 0; + virtual void setPrevWord(const int32_t *prevWord, int prevWordLength) = 0; + virtual ~IncrementalDecoderInterface() { }; +}; +} // namespace latinime + +#endif // LATINIME_INCREMENTAL_DECODER_INTERFACE_H |