Check for missing characters in User/Contacts dictionary as well.
Also accomodate for missing characters when doing diffs between words.main
parent
e5c7f0981d
commit
63fa90a791
|
@ -102,7 +102,10 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
public void getWords(final WordComposer codes, final WordCallback callback) {
|
public void getWords(final WordComposer codes, final WordCallback callback) {
|
||||||
mInputLength = codes.size();
|
mInputLength = codes.size();
|
||||||
mMaxDepth = mInputLength * 3;
|
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
|
@Override
|
||||||
|
@ -163,7 +166,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
* @param callback the callback class for adding a word
|
* @param callback the callback class for adding a word
|
||||||
*/
|
*/
|
||||||
protected void getWordsRec(List<Node> roots, final WordComposer codes, final char[] 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) {
|
WordCallback callback) {
|
||||||
final int count = roots.size();
|
final int count = roots.size();
|
||||||
final int codeSize = mInputLength;
|
final int codeSize = mInputLength;
|
||||||
|
@ -193,18 +196,20 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
getWordsRec(children, codes, word, depth + 1, completion, snr, inputIndex,
|
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
|
// Skip the ' and continue deeper
|
||||||
word[depth] = QUOTE;
|
word[depth] = c;
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
getWordsRec(children, codes, word, depth + 1, completion, snr, inputIndex,
|
getWordsRec(children, codes, word, depth + 1, completion, snr, inputIndex,
|
||||||
callback);
|
skipPos, callback);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
float addedAttenuation = (j > 0 ? 1f : 3f);
|
||||||
if (currentChars[j] == -1) {
|
if (currentChars[j] == -1) {
|
||||||
break;
|
break;
|
||||||
|
@ -223,11 +228,13 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
getWordsRec(children, codes, word, depth + 1,
|
getWordsRec(children, codes, word, depth + 1,
|
||||||
true, snr * addedAttenuation, inputIndex + 1, callback);
|
true, snr * addedAttenuation, inputIndex + 1,
|
||||||
|
skipPos, callback);
|
||||||
}
|
}
|
||||||
} else if (children != null) {
|
} else if (children != null) {
|
||||||
getWordsRec(children, codes, word, depth + 1,
|
getWordsRec(children, codes, word, depth + 1,
|
||||||
false, snr * addedAttenuation, inputIndex + 1, callback);
|
false, snr * addedAttenuation, inputIndex + 1,
|
||||||
|
skipPos, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,24 +113,34 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
mStringPool.add(sb);
|
mStringPool.add(sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean haveSufficientCommonality(String original, CharSequence suggestion) {
|
private boolean haveSufficientCommonality(String original, CharSequence suggestion) {
|
||||||
final int len = Math.min(original.length(), suggestion.length());
|
final int originalLength = original.length();
|
||||||
if (len <= 2) return true;
|
final int suggestionLength = suggestion.length();
|
||||||
|
final int minLength = Math.min(originalLength, suggestionLength);
|
||||||
|
if (minLength <= 2) return true;
|
||||||
int matching = 0;
|
int matching = 0;
|
||||||
for (int i = 0; i < len; i++) {
|
int lessMatching = 0; // Count matches if we skip one character
|
||||||
if (ExpandableDictionary.toLowerCase(original.charAt(i))
|
int i;
|
||||||
== ExpandableDictionary.toLowerCase(suggestion.charAt(i))) {
|
for (i = 0; i < minLength; i++) {
|
||||||
|
final char origChar = ExpandableDictionary.toLowerCase(original.charAt(i));
|
||||||
|
if (origChar == ExpandableDictionary.toLowerCase(suggestion.charAt(i))) {
|
||||||
matching++;
|
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;
|
return matching >= 2;
|
||||||
} else {
|
} else {
|
||||||
return matching > len / 2;
|
return matching > minLength / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of words that match the list of character codes passed in.
|
* Returns a list of words that match the list of character codes passed in.
|
||||||
* This list will be overwritten the next time this function is called.
|
* This list will be overwritten the next time this function is called.
|
||||||
|
|
Loading…
Reference in New Issue