BinaryDictionarypublic class BinaryDictionary extends Dictionary Implements a static, compacted, binary dictionary of standard words. |
Fields Summary |
---|
public static final int | MAX_WORD_LENGTH | private static final int | MAX_ALTERNATIVES | private static final int | MAX_WORDS | private static final int | TYPED_LETTER_MULTIPLIER | private int | mNativeDict | private int[] | mInputCodes | private WordCallback | mWordCallback | private char[] | mOutputChars | private int[] | mFrequencies |
Constructors Summary |
---|
public BinaryDictionary(android.content.Context context, int resId)Create a dictionary from a raw resource file
try {
System.loadLibrary("jni_latinime");
} catch (UnsatisfiedLinkError ule) {
Log.e("BinaryDictionary", "Could not load native library jni_latinime");
}
if (resId != 0) {
loadDictionary(context, resId);
}
|
Methods Summary |
---|
public synchronized void | close()
if (mNativeDict != 0) {
closeNative(mNativeDict);
mNativeDict = 0;
}
| private native void | closeNative(int dict)
| protected void | finalize()
close();
super.finalize();
| private native int | getSuggestionsNative(int dict, int[] inputCodes, int codesSize, char[] outputChars, int[] frequencies, int maxWordLength, int maxWords, int maxAlternatives)
| public void | getWords(WordComposer codes, WordCallback callback)
mWordCallback = callback;
final int codesSize = codes.size();
// Wont deal with really long words.
if (codesSize > MAX_WORD_LENGTH - 1) return;
Arrays.fill(mInputCodes, -1);
for (int i = 0; i < codesSize; i++) {
int[] alternatives = codes.getCodesAt(i);
System.arraycopy(alternatives, 0, mInputCodes, i * MAX_ALTERNATIVES,
Math.min(alternatives.length, MAX_ALTERNATIVES));
}
Arrays.fill(mOutputChars, (char) 0);
int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize, mOutputChars, mFrequencies,
MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
for (int j = 0; j < count; j++) {
if (mFrequencies[j] < 1) break;
int start = j * MAX_WORD_LENGTH;
int len = 0;
while (mOutputChars[start + len] != 0) {
len++;
}
if (len > 0) {
callback.addWord(mOutputChars, start, len, mFrequencies[j]);
}
}
| public boolean | isValidWord(java.lang.CharSequence word)
if (word == null) return false;
char[] chars = word.toString().toLowerCase().toCharArray();
return isValidWordNative(mNativeDict, chars, chars.length);
| private native boolean | isValidWordNative(int nativeData, char[] word, int wordLength)
| private final void | loadDictionary(android.content.Context context, int resId)
AssetManager am = context.getResources().getAssets();
String assetName = context.getResources().getString(resId);
mNativeDict = openNative(am, assetName, TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER);
| private native int | openNative(android.content.res.AssetManager am, java.lang.String resourcePath, int typedLetterMultiplier, int fullWordMultiplier)
| private native void | setParamsNative(int typedLetterMultiplier, int fullWordMultiplier)
|
|