aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-04-21 19:23:37 -0700
committerKeisuke Kuroyanagi <ksk@google.com>2014-04-22 12:01:33 -0700
commit89939b870876b36791a47470ce852e4fcdfe86f2 (patch)
treec3e9b3cb0f8c37d4ae5bb14335afa902a4fbd8e0 /java/src/com/android
parent903be5bbd33b664c7e691d8bee0dd4d6376947bc (diff)
downloadlatinime-89939b870876b36791a47470ce852e4fcdfe86f2.tar.gz
latinime-89939b870876b36791a47470ce852e4fcdfe86f2.tar.xz
latinime-89939b870876b36791a47470ce852e4fcdfe86f2.zip
Support creating BinaryDictionary without creating dict file.
Bug: 14166482 Change-Id: Ib065279f96e227ab0fee7c8141560c4ada744d3b
Diffstat (limited to 'java/src/com/android')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java36
1 files changed, 34 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index a351ee974..121fd5368 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
/**
* Implements a static, compacted, binary dictionary of standard words.
@@ -123,8 +124,7 @@ public final class BinaryDictionary extends Dictionary {
}
/**
- * Constructor for the binary dictionary. This is supposed to be called from the
- * dictionary factory.
+ * Constructs binary dictionary using existing dictionary file.
* @param filename the name of the file to read through native code.
* @param offset the offset of the dictionary data within the file.
* @param length the length of the binary data.
@@ -145,6 +145,38 @@ public final class BinaryDictionary extends Dictionary {
loadDictionary(filename, offset, length, isUpdatable);
}
+ /**
+ * Constructs binary dictionary on memory.
+ * @param filename the name of the file used to flush.
+ * @param useFullEditDistance whether to use the full edit distance in suggestions
+ * @param dictType the dictionary type, as a human-readable string
+ * @param formatVersion the format version of the dictionary
+ * @param attributeMap the attributes of the dictionary
+ */
+ @UsedForTesting
+ public BinaryDictionary(final String filename, final boolean useFullEditDistance,
+ final Locale locale, final String dictType, final long formatVersion,
+ final Map<String, String> attributeMap) {
+ super(dictType);
+ mLocale = locale;
+ mDictSize = 0;
+ mDictFilePath = filename;
+ // On memory dictionary is always updatable.
+ mIsUpdatable = true;
+ mHasUpdated = false;
+ mNativeSuggestOptions.setUseFullEditDistance(useFullEditDistance);
+ final String[] keyArray = new String[attributeMap.size()];
+ final String[] valueArray = new String[attributeMap.size()];
+ int index = 0;
+ for (final String key : attributeMap.keySet()) {
+ keyArray[index] = key;
+ valueArray[index] = attributeMap.get(key);
+ index++;
+ }
+ mNativeDict = openOnMemoryNative(formatVersion, locale.toString(), keyArray, valueArray);
+ }
+
+
static {
JniUtils.loadNativeLibrary();
}