Add support for German umlaut and French ligatures flags

Bug: 6202812
Change-Id: Ib4a7f96f6ef86c840069b15d04393f84d428c176
main
Jean Chalard 2012-04-06 15:30:42 +09:00
parent b8060399c7
commit f420df2823
4 changed files with 39 additions and 11 deletions

View File

@ -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.
@ -703,6 +705,14 @@ public class BinaryDictInputOutput {
return bigramFlags;
}
/**
* 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.
*
@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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);