parent
f25cc4405e
commit
fe9ec6bc7d
|
@ -633,7 +633,7 @@ public final class KeyboardState {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[keyboard=" + (mIsAlphabetMode ? mAlphabetShiftState.toString()
|
return "[keyboard=" + (mIsAlphabetMode ? mAlphabetShiftState.toString()
|
||||||
: (mIsSymbolShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS"))
|
: (mIsSymbolShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS"))
|
||||||
+ " shift=" + mShiftKeyState
|
+ " shift=" + mShiftKeyState
|
||||||
+ " symbol=" + mSymbolKeyState
|
+ " symbol=" + mSymbolKeyState
|
||||||
+ " switch=" + switchStateToString(mSwitchState) + "]";
|
+ " switch=" + switchStateToString(mSwitchState) + "]";
|
||||||
|
|
|
@ -101,7 +101,7 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
private native long openNative(String sourceDir, long dictOffset, long dictSize,
|
private native long openNative(String sourceDir, long dictOffset, long dictSize,
|
||||||
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions);
|
int maxWordLength, int maxWords, int maxPredictions);
|
||||||
private native void closeNative(long dict);
|
private native void closeNative(long dict);
|
||||||
private native int getFrequencyNative(long dict, int[] word);
|
private native int getFrequencyNative(long dict, int[] word);
|
||||||
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
|
private native boolean isValidBigramNative(long dict, int[] word1, int[] word2);
|
||||||
|
@ -116,8 +116,8 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
// TODO: Move native dict into session
|
// TODO: Move native dict into session
|
||||||
private final void loadDictionary(final String path, final long startOffset,
|
private final void loadDictionary(final String path, final long startOffset,
|
||||||
final long length) {
|
final long length) {
|
||||||
mNativeDict = openNative(path, startOffset, length, FULL_WORD_SCORE_MULTIPLIER,
|
mNativeDict = openNative(path, startOffset, length, MAX_WORD_LENGTH, MAX_WORDS,
|
||||||
MAX_WORD_LENGTH, MAX_WORDS, MAX_PREDICTIONS);
|
MAX_PREDICTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,11 +26,6 @@ import java.util.ArrayList;
|
||||||
* strokes.
|
* strokes.
|
||||||
*/
|
*/
|
||||||
public abstract class Dictionary {
|
public abstract class Dictionary {
|
||||||
/**
|
|
||||||
* The weight to give to a word if it's length is the same as the number of typed characters.
|
|
||||||
*/
|
|
||||||
protected static final int FULL_WORD_SCORE_MULTIPLIER = 2;
|
|
||||||
|
|
||||||
public static final int NOT_A_PROBABILITY = -1;
|
public static final int NOT_A_PROBABILITY = -1;
|
||||||
|
|
||||||
public static final String TYPE_USER_TYPED = "user_typed";
|
public static final String TYPE_USER_TYPED = "user_typed";
|
||||||
|
|
|
@ -31,6 +31,10 @@ import java.util.LinkedList;
|
||||||
* be searched for suggestions and valid words.
|
* be searched for suggestions and valid words.
|
||||||
*/
|
*/
|
||||||
public class ExpandableDictionary extends Dictionary {
|
public class ExpandableDictionary extends Dictionary {
|
||||||
|
/**
|
||||||
|
* The weight to give to a word if it's length is the same as the number of typed characters.
|
||||||
|
*/
|
||||||
|
private static final int FULL_WORD_SCORE_MULTIPLIER = 2;
|
||||||
|
|
||||||
// Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8.
|
// Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8.
|
||||||
protected static final int BIGRAM_MAX_FREQUENCY = 255;
|
protected static final int BIGRAM_MAX_FREQUENCY = 255;
|
||||||
|
|
|
@ -43,9 +43,8 @@ class ProximityInfo;
|
||||||
|
|
||||||
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
|
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
|
||||||
|
|
||||||
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object, jstring sourceDir,
|
||||||
jstring sourceDir, jlong dictOffset, jlong dictSize, jint fullWordMultiplier,
|
jlong dictOffset, jlong dictSize, jint maxWordLength, jint maxWords, jint maxPredictions) {
|
||||||
jint maxWordLength, jint maxWords, jint maxPredictions) {
|
|
||||||
PROF_OPEN;
|
PROF_OPEN;
|
||||||
PROF_START(66);
|
PROF_START(66);
|
||||||
const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir);
|
const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir);
|
||||||
|
@ -119,8 +118,8 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
releaseDictBuf(dictBuf, 0, 0);
|
releaseDictBuf(dictBuf, 0, 0);
|
||||||
#endif // USE_MMAP_FOR_DICTIONARY
|
#endif // USE_MMAP_FOR_DICTIONARY
|
||||||
} else {
|
} else {
|
||||||
dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust,
|
dictionary = new Dictionary(dictBuf, static_cast<int>(dictSize), fd, adjust, maxWordLength,
|
||||||
fullWordMultiplier, maxWordLength, maxWords, maxPredictions);
|
maxWords, maxPredictions);
|
||||||
}
|
}
|
||||||
PROF_END(66);
|
PROF_END(66);
|
||||||
PROF_CLOSE;
|
PROF_CLOSE;
|
||||||
|
@ -272,7 +271,7 @@ static void releaseDictBuf(const void *dictBuf, const size_t length, const int f
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod sMethods[] = {
|
static JNINativeMethod sMethods[] = {
|
||||||
{"openNative", "(Ljava/lang/String;JJIIII)J",
|
{"openNative", "(Ljava/lang/String;JJIII)J",
|
||||||
reinterpret_cast<void *>(latinime_BinaryDictionary_open)},
|
reinterpret_cast<void *>(latinime_BinaryDictionary_open)},
|
||||||
{"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)},
|
{"closeNative", "(J)V", reinterpret_cast<void *>(latinime_BinaryDictionary_close)},
|
||||||
{"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I",
|
{"getSuggestionsNative", "(JJJ[I[I[I[I[IIIZ[IZ[I[I[I[I)I",
|
||||||
|
|
|
@ -29,13 +29,13 @@
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
// TODO: Change the type of all keyCodes to uint32_t
|
// TODO: Change the type of all keyCodes to uint32_t
|
||||||
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
|
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength,
|
||||||
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions)
|
int maxWords, int maxPredictions)
|
||||||
: mDict(static_cast<unsigned char *>(dict)),
|
: mDict(static_cast<unsigned char *>(dict)),
|
||||||
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
|
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
|
||||||
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
|
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
|
||||||
mUnigramDictionary(new UnigramDictionary(mOffsetDict, fullWordMultiplier, maxWordLength,
|
mUnigramDictionary(new UnigramDictionary(mOffsetDict, maxWordLength, maxWords,
|
||||||
maxWords, BinaryFormat::getFlags(mDict))),
|
BinaryFormat::getFlags(mDict))),
|
||||||
mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)),
|
mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)),
|
||||||
mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) {
|
mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) {
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
|
|
|
@ -41,8 +41,8 @@ class Dictionary {
|
||||||
const static int KIND_SHORTCUT = 7; // A shortcut
|
const static int KIND_SHORTCUT = 7; // A shortcut
|
||||||
const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
|
const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
|
||||||
|
|
||||||
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int fullWordMultiplier,
|
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int maxWordLength,
|
||||||
int maxWordLength, int maxWords, int maxPredictions);
|
int maxWords, int maxPredictions);
|
||||||
|
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
||||||
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
|
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
|
||||||
|
|
|
@ -41,10 +41,9 @@ const UnigramDictionary::digraph_t UnigramDictionary::FRENCH_LIGATURES_DIGRAPHS[
|
||||||
{ 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE
|
{ 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE
|
||||||
|
|
||||||
// TODO: check the header
|
// TODO: check the header
|
||||||
UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int fullWordMultiplier,
|
UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, int maxWordLength,
|
||||||
int maxWordLength, int maxWords, const unsigned int flags)
|
int maxWords, const unsigned int flags)
|
||||||
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
|
: DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
|
||||||
FULL_WORD_MULTIPLIER(fullWordMultiplier), // TODO : remove this variable.
|
|
||||||
ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
|
ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
AKLOGI("UnigramDictionary - constructor");
|
AKLOGI("UnigramDictionary - constructor");
|
||||||
|
|
|
@ -39,8 +39,8 @@ class UnigramDictionary {
|
||||||
static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0;
|
static const int FLAG_MULTIPLE_SUGGEST_ABORT = 0;
|
||||||
static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1;
|
static const int FLAG_MULTIPLE_SUGGEST_SKIP = 1;
|
||||||
static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2;
|
static const int FLAG_MULTIPLE_SUGGEST_CONTINUE = 2;
|
||||||
UnigramDictionary(const uint8_t *const streamStart, int fullWordMultiplier, int maxWordLength,
|
UnigramDictionary(const uint8_t *const streamStart, int maxWordLength, int maxWords,
|
||||||
int maxWords, const unsigned int flags);
|
const unsigned int flags);
|
||||||
int getFrequency(const int *const inWord, const int length) const;
|
int getFrequency(const int *const inWord, const int length) const;
|
||||||
int getBigramPosition(int pos, int *word, int offset, int length) const;
|
int getBigramPosition(int pos, int *word, int offset, int length) const;
|
||||||
int getSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
|
int getSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
|
||||||
|
@ -114,7 +114,6 @@ class UnigramDictionary {
|
||||||
const uint8_t *const DICT_ROOT;
|
const uint8_t *const DICT_ROOT;
|
||||||
const int MAX_WORD_LENGTH;
|
const int MAX_WORD_LENGTH;
|
||||||
const int MAX_WORDS;
|
const int MAX_WORDS;
|
||||||
const int FULL_WORD_MULTIPLIER;
|
|
||||||
const int ROOT_POS;
|
const int ROOT_POS;
|
||||||
const int MAX_DIGRAPH_SEARCH_DEPTH;
|
const int MAX_DIGRAPH_SEARCH_DEPTH;
|
||||||
const int FLAGS;
|
const int FLAGS;
|
||||||
|
|
Loading…
Reference in New Issue