aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java25
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java10
-rw-r--r--tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java12
-rw-r--r--tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java3
4 files changed, 39 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index 820c0a59c..d22332116 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
+import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -126,8 +127,9 @@ public class BinaryDictInputOutput {
private static final int NOT_A_VERSION_NUMBER = -1;
private static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
- // No options yet, reserved for future use.
- private static final int OPTIONS = 0;
+ // These options need to be the same numeric values as the one in the native reading code.
+ private static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
+ private static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
// TODO: Make this value adaptative to content data, store it in the header, and
// use it in the reading code.
@@ -704,6 +706,14 @@ public class BinaryDictInputOutput {
}
/**
+ * Makes the 2-byte value for options flags.
+ */
+ private static final int makeOptionsValue(final DictionaryOptions options) {
+ return (options.mFrenchLigatureProcessing ? FRENCH_LIGATURE_PROCESSING_FLAG : 0)
+ + (options.mGermanUmlautProcessing ? GERMAN_UMLAUT_PROCESSING_FLAG : 0);
+ }
+
+ /**
* Makes the flag value for a shortcut.
*
* @param more whether there are more attributes after this one.
@@ -918,8 +928,9 @@ public class BinaryDictInputOutput {
buffer[index++] = (byte) (0xFF & version);
}
// Options flags
- buffer[index++] = (byte) (0xFF & (OPTIONS >> 8));
- buffer[index++] = (byte) (0xFF & OPTIONS);
+ final int options = makeOptionsValue(dict.mOptions);
+ buffer[index++] = (byte) (0xFF & (options >> 8));
+ buffer[index++] = (byte) (0xFF & options);
if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
final int headerSizeOffset = index;
index += 4; // Size of the header size
@@ -1218,7 +1229,7 @@ public class BinaryDictInputOutput {
}
// Read options
- source.readUnsignedShort();
+ final int optionsFlags = source.readUnsignedShort();
final long headerSize;
final HashMap<String, String> options = new HashMap<String, String>();
@@ -1240,7 +1251,9 @@ public class BinaryDictInputOutput {
final Node root = readNode(source, headerSize, reverseNodeMapping, reverseGroupMapping);
FusionDictionary newDict = new FusionDictionary(root,
- new FusionDictionary.DictionaryOptions(options));
+ new FusionDictionary.DictionaryOptions(options,
+ 0 != (optionsFlags & GERMAN_UMLAUT_PROCESSING_FLAG),
+ 0 != (optionsFlags & FRENCH_LIGATURE_PROCESSING_FLAG)));
if (null != dict) {
for (Word w : dict) {
newDict.add(w.mWord, w.mFrequency, w.mShortcutTargets, w.mBigrams);
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index 3515287b0..40bcfc3aa 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -239,13 +239,17 @@ public class FusionDictionary implements Iterable<Word> {
* There are no options at the moment, so this class is empty.
*/
public static class DictionaryOptions {
- final HashMap<String, String> mAttributes;
- public DictionaryOptions(final HashMap<String, String> attributes) {
+ public final boolean mGermanUmlautProcessing;
+ public final boolean mFrenchLigatureProcessing;
+ public final HashMap<String, String> mAttributes;
+ public DictionaryOptions(final HashMap<String, String> attributes,
+ final boolean germanUmlautProcessing, final boolean frenchLigatureProcessing) {
mAttributes = attributes;
+ mGermanUmlautProcessing = germanUmlautProcessing;
+ mFrenchLigatureProcessing = frenchLigatureProcessing;
}
}
-
public final DictionaryOptions mOptions;
public final Node mRoot;
diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java b/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java
index 0acd1b2a9..dfc8baa4d 100644
--- a/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java
+++ b/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java
@@ -51,6 +51,10 @@ public class XmlDictInputOutput {
private static final int SHORTCUT_ONLY_DEFAULT_FREQ = 1;
+ private static final String OPTIONS_KEY = "options";
+ private static final String GERMAN_UMLAUT_PROCESSING_OPTION = "german_umlaut_processing";
+ private static final String FRENCH_LIGATURE_PROCESSING_OPTION = "french_ligature_processing";
+
/**
* SAX handler for a unigram XML file.
*/
@@ -114,7 +118,13 @@ public class XmlDictInputOutput {
final String attrName = attrs.getLocalName(attrIndex);
attributes.put(attrName, attrs.getValue(attrIndex));
}
- mDictionary = new FusionDictionary(new Node(), new DictionaryOptions(attributes));
+ final String optionsString = attributes.get(OPTIONS_KEY);
+ final boolean processUmlauts =
+ GERMAN_UMLAUT_PROCESSING_OPTION.equals(optionsString);
+ final boolean processLigatures =
+ FRENCH_LIGATURE_PROCESSING_OPTION.equals(optionsString);
+ mDictionary = new FusionDictionary(new Node(), new DictionaryOptions(attributes,
+ processUmlauts, processLigatures));
} else {
mState = UNKNOWN;
}
diff --git a/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java b/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java
index e19c7d53b..191eb804d 100644
--- a/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java
+++ b/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java
@@ -41,7 +41,8 @@ public class BinaryDictInputOutputTest extends TestCase {
// that it does not contain any duplicates.
public void testFlattenNodes() {
final FusionDictionary dict = new FusionDictionary(new Node(),
- new DictionaryOptions(new HashMap<String, String>()));
+ new DictionaryOptions(new HashMap<String, String>(),
+ false /* germanUmlautProcessing */, false /* frenchLigatureProcessing */));
dict.add("foo", 1, null, null);
dict.add("fta", 1, null, null);
dict.add("ftb", 1, null, null);