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

Commit e7a2512a authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add Utils.equalsIgnoreCase methods

This change also corrects usage of "frequency", "priority" and "score"
* Frequency is the relative probability in dictionary.
* Score is the relative probability in suggestions.
* Priority is kind a sorted score.

Change-Id: Iafb135a4ecdb401cc505014a07c74dfcac44d699
parent 027992af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -18,3 +18,7 @@
-keep class com.android.inputmethod.latin.AutoCorrection {
  java.lang.CharSequence getAutoCorrectionWord();
}

-keep class com.android.inputmethod.latin.Utils {
  boolean equalsIgnoreCase(...);
}
+5 −5
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class AutoCorrection {
    }

    public void updateAutoCorrectionStatus(Map<String, Dictionary> dictionaries,
            WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] priorities,
            WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
            CharSequence typedWord, double autoCorrectionThreshold, int correctionMode,
            CharSequence quickFixedWord, CharSequence whitelistedWord) {
        if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
@@ -62,7 +62,7 @@ public class AutoCorrection {
            mHasAutoCorrection = true;
            mAutoCorrectionWord = quickFixedWord;
        } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, correctionMode,
                priorities, typedWord, autoCorrectionThreshold)) {
                sortedScores, typedWord, autoCorrectionThreshold)) {
            mHasAutoCorrection = true;
            mAutoCorrectionWord = suggestions.get(0);
        }
@@ -114,13 +114,13 @@ public class AutoCorrection {
    }

    private boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
            ArrayList<CharSequence> suggestions, int correctionMode, int[] priorities,
            ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores,
            CharSequence typedWord, double autoCorrectionThreshold) {
        if (wordComposer.size() > 1 && (correctionMode == Suggest.CORRECTION_FULL
                || correctionMode == Suggest.CORRECTION_FULL_BIGRAM)
                && typedWord != null && suggestions.size() > 0 && priorities.length > 0) {
                && typedWord != null && suggestions.size() > 0 && sortedScores.length > 0) {
            final CharSequence autoCorrectionCandidate = suggestions.get(0);
            final int autoCorrectionCandidateScore = priorities[0];
            final int autoCorrectionCandidateScore = sortedScores[0];
            // TODO: when the normalized score of the first suggestion is nearly equals to
            //       the normalized score of the second suggestion, behave less aggressive.
            mNormalizedScore = Utils.calcNormalizedScore(
+15 −15
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ public class BinaryDictionary extends Dictionary {
    private final int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_PROXIMITY_CHARS_SIZE];
    private final char[] mOutputChars = new char[MAX_WORD_LENGTH * MAX_WORDS];
    private final char[] mOutputChars_bigrams = new char[MAX_WORD_LENGTH * MAX_BIGRAMS];
    private final int[] mFrequencies = new int[MAX_WORDS];
    private final int[] mFrequencies_bigrams = new int[MAX_BIGRAMS];
    private final int[] mScores = new int[MAX_WORDS];
    private final int[] mBigramScores = new int[MAX_BIGRAMS];

    private final KeyboardSwitcher mKeyboardSwitcher = KeyboardSwitcher.getInstance();
    private final SubtypeSwitcher mSubtypeSwitcher = SubtypeSwitcher.getInstance();
@@ -149,14 +149,14 @@ public class BinaryDictionary extends Dictionary {
    private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
    private native int getSuggestionsNative(int dict, int proximityInfo, int[] xCoordinates,
            int[] yCoordinates, int[] inputCodes, int codesSize, int flags, char[] outputChars,
            int[] frequencies);
            int[] scores);
    private native int getBigramsNative(int dict, char[] prevWord, int prevWordLength,
            int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies,
            int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
            int maxWordLength, int maxBigrams, int maxAlternatives);

    private final void loadDictionary(String path, long startOffset, long length) {
        mNativeDict = openNative(path, startOffset, length,
                    TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER,
                    TYPED_LETTER_MULTIPLIER, FULL_WORD_SCORE_MULTIPLIER,
                    MAX_WORD_LENGTH, MAX_WORDS, MAX_PROXIMITY_CHARS_SIZE);
        mDictLength = length;
    }
@@ -168,7 +168,7 @@ public class BinaryDictionary extends Dictionary {

        char[] chars = previousWord.toString().toCharArray();
        Arrays.fill(mOutputChars_bigrams, (char) 0);
        Arrays.fill(mFrequencies_bigrams, 0);
        Arrays.fill(mBigramScores, 0);

        int codesSize = codes.size();
        Arrays.fill(mInputCodes, -1);
@@ -177,18 +177,18 @@ public class BinaryDictionary extends Dictionary {
                Math.min(alternatives.length, MAX_PROXIMITY_CHARS_SIZE));

        int count = getBigramsNative(mNativeDict, chars, chars.length, mInputCodes, codesSize,
                mOutputChars_bigrams, mFrequencies_bigrams, MAX_WORD_LENGTH, MAX_BIGRAMS,
                mOutputChars_bigrams, mBigramScores, MAX_WORD_LENGTH, MAX_BIGRAMS,
                MAX_PROXIMITY_CHARS_SIZE);

        for (int j = 0; j < count; ++j) {
            if (mFrequencies_bigrams[j] < 1) break;
            if (mBigramScores[j] < 1) break;
            final int start = j * MAX_WORD_LENGTH;
            int len = 0;
            while (len <  MAX_WORD_LENGTH && mOutputChars_bigrams[start + len] != 0) {
                ++len;
            }
            if (len > 0) {
                callback.addWord(mOutputChars_bigrams, start, len, mFrequencies_bigrams[j],
                callback.addWord(mOutputChars_bigrams, start, len, mBigramScores[j],
                        mDicTypeId, DataType.BIGRAM);
            }
        }
@@ -197,17 +197,17 @@ public class BinaryDictionary extends Dictionary {
    @Override
    public void getWords(final WordComposer codes, final WordCallback callback) {
        final int count = getSuggestions(codes, mKeyboardSwitcher.getLatinKeyboard(),
                mOutputChars, mFrequencies);
                mOutputChars, mScores);

        for (int j = 0; j < count; ++j) {
            if (mFrequencies[j] < 1) break;
            if (mScores[j] < 1) break;
            final int start = j * MAX_WORD_LENGTH;
            int len = 0;
            while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
                ++len;
            }
            if (len > 0) {
                callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
                callback.addWord(mOutputChars, start, len, mScores[j], mDicTypeId,
                        DataType.UNIGRAM);
            }
        }
@@ -218,7 +218,7 @@ public class BinaryDictionary extends Dictionary {
    }

    /* package for test */ int getSuggestions(final WordComposer codes, final Keyboard keyboard,
            char[] outputChars, int[] frequencies) {
            char[] outputChars, int[] scores) {
        if (!isValidDictionary()) return -1;

        final int codesSize = codes.size();
@@ -232,12 +232,12 @@ public class BinaryDictionary extends Dictionary {
                    Math.min(alternatives.length, MAX_PROXIMITY_CHARS_SIZE));
        }
        Arrays.fill(outputChars, (char) 0);
        Arrays.fill(frequencies, 0);
        Arrays.fill(scores, 0);

        return getSuggestionsNative(
                mNativeDict, keyboard.getProximityInfo(),
                codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
                mFlags, outputChars, frequencies);
                mFlags, outputChars, scores);
    }

    @Override
+4 −4
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ 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_FREQ_MULTIPLIER = 2;
    protected static final int FULL_WORD_SCORE_MULTIPLIER = 2;

    public static enum DataType {
        UNIGRAM, BIGRAM
@@ -42,17 +42,17 @@ public abstract class Dictionary {
    public interface WordCallback {
        /**
         * Adds a word to a list of suggestions. The word is expected to be ordered based on
         * the provided frequency.
         * the provided score.
         * @param word the character array containing the word
         * @param wordOffset starting offset of the word in the character array
         * @param wordLength length of valid characters in the character array
         * @param frequency the frequency of occurrence. This is normalized between 1 and 255, but
         * @param score the score of occurrence. This is normalized between 1 and 255, but
         * can exceed those limits
         * @param dicTypeId of the dictionary where word was from
         * @param dataType tells type of this data
         * @return true if the word was added, false if no more words are required
         */
        boolean addWord(char[] word, int wordOffset, int wordLength, int frequency, int dicTypeId,
        boolean addWord(char[] word, int wordOffset, int wordLength, int score, int dicTypeId,
                DataType dataType);
    }

+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ public class ExpandableDictionary extends Dictionary {
                                    final int finalFreq;
                                    if (skipPos < 0) {
                                        finalFreq = freq * snr * addedAttenuation
                                                * FULL_WORD_FREQ_MULTIPLIER;
                                                * FULL_WORD_SCORE_MULTIPLIER;
                                    } else {
                                        finalFreq = computeSkippedWordFinalFreq(freq,
                                                snr * addedAttenuation, mInputLength);
Loading