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

Commit 63fa90a7 authored by Amith Yamasani's avatar Amith Yamasani Committed by Jean-Baptiste Queru
Browse files

Check for missing characters in User/Contacts dictionary as well.

Also accomodate for missing characters when doing diffs between words.
parent e5c7f098
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -102,7 +102,10 @@ public class ExpandableDictionary extends Dictionary {
    public void getWords(final WordComposer codes, final WordCallback callback) {
        mInputLength = codes.size();
        mMaxDepth = mInputLength * 3;
        getWordsRec(mRoots, codes, mWordBuilder, 0, false, 1.0f, 0, callback);
        getWordsRec(mRoots, codes, mWordBuilder, 0, false, 1.0f, 0, -1, callback);
        for (int i = 0; i < mInputLength; i++) {
            getWordsRec(mRoots, codes, mWordBuilder, 0, false, 1.0f, 0, i, callback);
        }
    }

    @Override
@@ -163,7 +166,7 @@ public class ExpandableDictionary extends Dictionary {
     * @param callback the callback class for adding a word
     */
    protected void getWordsRec(List<Node> roots, final WordComposer codes, final char[] word, 
            final int depth, boolean completion, float snr, int inputIndex,
            final int depth, boolean completion, float snr, int inputIndex, int skipPos,
            WordCallback callback) {
        final int count = roots.size();
        final int codeSize = mInputLength;
@@ -194,17 +197,19 @@ public class ExpandableDictionary extends Dictionary {
                }
                if (children != null) {
                    getWordsRec(children, codes, word, depth + 1, completion, snr, inputIndex,
                            callback);
                            skipPos, callback);
                }
            } else if (c == QUOTE && currentChars[0] != QUOTE) {
            } else if ((c == QUOTE && currentChars[0] != QUOTE) || depth == skipPos) {
                // Skip the ' and continue deeper
                word[depth] = QUOTE;
                word[depth] = c;
                if (children != null) {
                    getWordsRec(children, codes, word, depth + 1, completion, snr, inputIndex, 
                            callback);
                            skipPos, callback);
                }
            } else {
                for (int j = 0; j < currentChars.length; j++) {
                // Don't use alternatives if we're looking for missing characters
                final int alternativesSize = skipPos >= 0? 1 : currentChars.length;
                for (int j = 0; j < alternativesSize; j++) {
                    float addedAttenuation = (j > 0 ? 1f : 3f);
                    if (currentChars[j] == -1) {
                        break;
@@ -223,11 +228,13 @@ public class ExpandableDictionary extends Dictionary {
                            }
                            if (children != null) {
                                getWordsRec(children, codes, word, depth + 1, 
                                        true, snr * addedAttenuation, inputIndex + 1, callback);
                                        true, snr * addedAttenuation, inputIndex + 1,
                                        skipPos, callback);
                            }
                        } else if (children != null) {
                            getWordsRec(children, codes, word, depth + 1, 
                                    false, snr * addedAttenuation, inputIndex + 1, callback);
                                    false, snr * addedAttenuation, inputIndex + 1,
                                    skipPos, callback);
                        }
                    }
                }
+19 −9
Original line number Diff line number Diff line
@@ -115,19 +115,29 @@ public class Suggest implements Dictionary.WordCallback {
    }

    private boolean haveSufficientCommonality(String original, CharSequence suggestion) {
        final int len = Math.min(original.length(), suggestion.length());
        if (len <= 2) return true;
        final int originalLength = original.length();
        final int suggestionLength = suggestion.length();
        final int minLength = Math.min(originalLength, suggestionLength);
        if (minLength <= 2) return true;
        int matching = 0;
        for (int i = 0; i < len; i++) {
            if (ExpandableDictionary.toLowerCase(original.charAt(i)) 
                    == ExpandableDictionary.toLowerCase(suggestion.charAt(i))) {
        int lessMatching = 0; // Count matches if we skip one character
        int i;
        for (i = 0; i < minLength; i++) {
            final char origChar = ExpandableDictionary.toLowerCase(original.charAt(i));
            if (origChar == ExpandableDictionary.toLowerCase(suggestion.charAt(i))) {
                matching++;
                lessMatching++;
            } else if (i + 1 < suggestionLength
                    && origChar == ExpandableDictionary.toLowerCase(suggestion.charAt(i + 1))) {
                lessMatching++;
            }
        }
        if (len <= 4) {
        matching = Math.max(matching, lessMatching);

        if (minLength <= 4) {
            return matching >= 2;
        } else {
            return matching > len / 2;
            return matching > minLength / 2;
        }
    }