Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68eb1b19 authored by Jean-Baptiste Queru's avatar Jean-Baptiste Queru
Browse files

eclair snapshot

parent 399d49b7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -4,9 +4,11 @@
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
    <uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
    <uses-permission android:name="android.permission.BACKUP_DATA" />

    <application android:label="@string/english_ime_name"
            android:backupAgent="LatinIMEBackupAgent">
            android:backupAgent="LatinIMEBackupAgent"
            android:killAfterRestore="false">

        <service android:name="LatinIME"
                android:label="@string/english_ime_name"
+18 −18
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ static jint latinime_BinaryDictionary_open
static int latinime_BinaryDictionary_getSuggestions(
        JNIEnv *env, jobject object, jint dict, jintArray inputArray, jint arraySize,
        jcharArray outputArray, jintArray frequencyArray, jint maxWordLength, jint maxWords,
        jint maxAlternatives)
        jint maxAlternatives, jint skipPos)
{
    Dictionary *dictionary = (Dictionary*) dict;
    if (dictionary == NULL)
@@ -98,7 +98,7 @@ static int latinime_BinaryDictionary_getSuggestions(
    jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);

    int count = dictionary->getSuggestions(inputCodes, arraySize, (unsigned short*) outputChars, frequencies,
            maxWordLength, maxWords, maxAlternatives);
            maxWordLength, maxWords, maxAlternatives, skipPos);
    
    env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
    env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
@@ -134,7 +134,7 @@ static JNINativeMethod gMethods[] = {
    {"openNative",           "(Landroid/content/res/AssetManager;Ljava/lang/String;II)I",
                                          (void*)latinime_BinaryDictionary_open},
    {"closeNative",          "(I)V",            (void*)latinime_BinaryDictionary_close},
    {"getSuggestionsNative", "(I[II[C[IIII)I",  (void*)latinime_BinaryDictionary_getSuggestions},
    {"getSuggestionsNative", "(I[II[C[IIIII)I",  (void*)latinime_BinaryDictionary_getSuggestions},
    {"isValidWordNative",    "(I[CI)Z",         (void*)latinime_BinaryDictionary_isValidWord}
};

+33 −25
Original line number Diff line number Diff line
@@ -49,11 +49,8 @@ Dictionary::~Dictionary()
}

int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
        int maxWordLength, int maxWords, int maxAlternatives)
        int maxWordLength, int maxWords, int maxAlternatives, int skipPos)
{
    memset(frequencies, 0, maxWords * sizeof(*frequencies));
    memset(outWords, 0, maxWords * maxWordLength * sizeof(*outWords));

    mFrequencies = frequencies;
    mOutputChars = outWords;
    mInputCodes = codes;
@@ -62,8 +59,10 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
    mMaxWordLength = maxWordLength;
    mMaxWords = maxWords;
    mWords = 0;
    mSkipPos = skipPos;
    mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2;

    getWordsRec(0, 0, mInputLength * 3, false, 1, 0);
    getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0);

    if (DEBUG_DICT) LOGI("Returning %d words", mWords);
    return mWords;
@@ -110,7 +109,11 @@ bool
Dictionary::addWord(unsigned short *word, int length, int frequency)
{
    word[length] = 0;
    if (DEBUG_DICT) LOGI("Found word = %s, freq = %d : \n", word, frequency);
    if (DEBUG_DICT) {
        char s[length + 1];
        for (int i = 0; i <= length; i++) s[i] = word[i];
        LOGI("Found word = %s, freq = %d : \n", s, frequency);
    }

    // Find the right insertion point
    int insertAt = 0;
@@ -144,17 +147,15 @@ Dictionary::addWord(unsigned short *word, int length, int frequency)
}

unsigned short
Dictionary::toLowerCase(unsigned short c, const int depth) {
Dictionary::toLowerCase(unsigned short c) {
    if (c < sizeof(BASE_CHARS) / sizeof(BASE_CHARS[0])) {
        c = BASE_CHARS[c];
    }
    if (depth == 0) {
    if (c >='A' && c <= 'Z') {
        c |= 32;
    } else if (c > 127) {
        c = u_tolower(c);
    }
    }
    return c;
}

@@ -178,12 +179,16 @@ Dictionary::sameAsTyped(unsigned short *word, int length)
static char QUOTE = '\'';

void
Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int snr, int inputIndex)
Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int snr, int inputIndex,
                        int diffs)
{
    // Optimization: Prune out words that are too long compared to how much was typed.
    if (depth > maxDepth) {
        return;
    }
    if (diffs > mMaxEditDistance) {
        return;
    }
    int count = getCount(&pos);
    int *currentChars = NULL;
    if (mInputLength <= inputIndex) {
@@ -194,7 +199,7 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s

    for (int i = 0; i < count; i++) {
        unsigned short c = getChar(&pos);
        unsigned short lowerC = toLowerCase(c, depth);
        unsigned short lowerC = toLowerCase(c);
        bool terminal = getTerminal(&pos);
        int childrenAddress = getAddress(&pos);
        int freq = 1;
@@ -207,38 +212,41 @@ Dictionary::getWordsRec(int pos, int depth, int maxDepth, bool completion, int s
            }
            if (childrenAddress != 0) {
                getWordsRec(childrenAddress, depth + 1, maxDepth,
                            completion, snr, inputIndex);
                            completion, snr, inputIndex, diffs);
            }
        } else if (c == QUOTE && currentChars[0] != QUOTE) {
            // Skip the ' and continue deeper
            mWord[depth] = QUOTE;
        } else if (c == QUOTE && currentChars[0] != QUOTE || mSkipPos == depth) {
            // Skip the ' or other letter and continue deeper
            mWord[depth] = c;
            if (childrenAddress != 0) {
                getWordsRec(childrenAddress, depth + 1, maxDepth, false, snr, inputIndex);
                getWordsRec(childrenAddress, depth + 1, maxDepth, false, snr, inputIndex, diffs);
            }
        } else {
            int j = 0;
            while (currentChars[j] > 0) {
                int addedWeight = j == 0 ? mTypedLetterMultiplier : 1;
                if (currentChars[j] == lowerC || currentChars[j] == c) {
                    int addedWeight = j == 0 ? mTypedLetterMultiplier : 1;
                    mWord[depth] = c;
                    if (mInputLength == inputIndex + 1) {
                        if (terminal) {
                            if (//INCLUDE_TYPED_WORD_IF_VALID ||
                                !sameAsTyped(mWord, depth + 1)) {
                                addWord(mWord, depth + 1,
                                    (freq * snr * addedWeight * mFullWordMultiplier));
                                int finalFreq = freq * snr * addedWeight;
                                if (mSkipPos < 0) finalFreq *= mFullWordMultiplier;
                                addWord(mWord, depth + 1, finalFreq);
                            }
                        }
                        if (childrenAddress != 0) {
                            getWordsRec(childrenAddress, depth + 1,
                                    maxDepth, true, snr * addedWeight, inputIndex + 1);
                                    maxDepth, true, snr * addedWeight, inputIndex + 1,
                                    diffs + (j > 0));
                        }
                    } else if (childrenAddress != 0) {
                        getWordsRec(childrenAddress, depth + 1, maxDepth,
                                false, snr * addedWeight, inputIndex + 1);
                                false, snr * addedWeight, inputIndex + 1, diffs + (j > 0));
                    }
                }
                j++;
                if (mSkipPos >= 0) break;
            }
        }
    }
+5 −3
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class Dictionary {
public:
    Dictionary(void *dict, int typedLetterMultipler, int fullWordMultiplier);
    int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
        int maxWordLength, int maxWords, int maxAlternatives);
        int maxWordLength, int maxWords, int maxAlternatives, int skipPos);
    bool isValidWord(unsigned short *word, int length);
    void setAsset(void *asset) { mAsset = asset; }
    void *getAsset() { return mAsset; }
@@ -49,9 +49,9 @@ private:

    bool sameAsTyped(unsigned short *word, int length);
    bool addWord(unsigned short *word, int length, int frequency);
    unsigned short toLowerCase(unsigned short c, int depth);
    unsigned short toLowerCase(unsigned short c);
    void getWordsRec(int pos, int depth, int maxDepth, bool completion, int frequency,
            int inputIndex);
            int inputIndex, int diffs);
    bool isValidWordRec(int pos, unsigned short *word, int offset, int length);

    unsigned char *mDict;
@@ -66,6 +66,8 @@ private:
    int mInputLength;
    int mMaxAlternatives;
    unsigned short mWord[128];
    int mSkipPos;
    int mMaxEditDistance;

    int mFullWordMultiplier;
    int mTypedLetterMultiplier;
+2.26 KiB
Loading image diff...
Loading