am 32e85fda: Merge "Have makedict support the new file format." into jb-mr1-dev

* commit '32e85fdacfb4c865c7e1565d80697e97e21f3484':
  Have makedict support the new file format.
main
Jean Chalard 2012-09-10 01:51:41 -07:00 committed by Android Git Automerger
commit 299c32929e
1 changed files with 21 additions and 27 deletions

View File

@ -42,40 +42,35 @@ import org.xml.sax.SAXException;
public class DictionaryMaker { public class DictionaryMaker {
static class Arguments { static class Arguments {
private final static String OPTION_VERSION_2 = "-2"; private static final String OPTION_VERSION_1 = "-1";
private final static String OPTION_INPUT_SOURCE = "-s"; private static final String OPTION_VERSION_2 = "-2";
private final static String OPTION_INPUT_BIGRAM_XML = "-b"; private static final String OPTION_VERSION_3 = "-3";
private final static String OPTION_INPUT_SHORTCUT_XML = "-c"; private static final String OPTION_INPUT_SOURCE = "-s";
private final static String OPTION_OUTPUT_BINARY = "-d"; private static final String OPTION_INPUT_BIGRAM_XML = "-b";
private final static String OPTION_OUTPUT_BINARY_FORMAT_VERSION_1 = "-d1"; private static final String OPTION_INPUT_SHORTCUT_XML = "-c";
private final static String OPTION_OUTPUT_XML = "-x"; private static final String OPTION_OUTPUT_BINARY = "-d";
private final static String OPTION_HELP = "-h"; private static final String OPTION_OUTPUT_XML = "-x";
private static final String OPTION_HELP = "-h";
public final String mInputBinary; public final String mInputBinary;
public final String mInputUnigramXml; public final String mInputUnigramXml;
public final String mInputShortcutXml; public final String mInputShortcutXml;
public final String mInputBigramXml; public final String mInputBigramXml;
public final String mOutputBinary; public final String mOutputBinary;
public final String mOutputBinaryFormat1;
public final String mOutputXml; public final String mOutputXml;
public final int mOutputBinaryFormatVersion;
private void checkIntegrity() throws IOException { private void checkIntegrity() throws IOException {
checkHasExactlyOneInput(); checkHasExactlyOneInput();
checkHasAtLeastOneOutput(); checkHasAtLeastOneOutput();
checkNotSameFile(mInputBinary, mOutputBinary); checkNotSameFile(mInputBinary, mOutputBinary);
checkNotSameFile(mInputBinary, mOutputBinaryFormat1);
checkNotSameFile(mInputBinary, mOutputXml); checkNotSameFile(mInputBinary, mOutputXml);
checkNotSameFile(mInputUnigramXml, mOutputBinary); checkNotSameFile(mInputUnigramXml, mOutputBinary);
checkNotSameFile(mInputUnigramXml, mOutputBinaryFormat1);
checkNotSameFile(mInputUnigramXml, mOutputXml); checkNotSameFile(mInputUnigramXml, mOutputXml);
checkNotSameFile(mInputShortcutXml, mOutputBinary); checkNotSameFile(mInputShortcutXml, mOutputBinary);
checkNotSameFile(mInputShortcutXml, mOutputBinaryFormat1);
checkNotSameFile(mInputShortcutXml, mOutputXml); checkNotSameFile(mInputShortcutXml, mOutputXml);
checkNotSameFile(mInputBigramXml, mOutputBinary); checkNotSameFile(mInputBigramXml, mOutputBinary);
checkNotSameFile(mInputBigramXml, mOutputBinaryFormat1);
checkNotSameFile(mInputBigramXml, mOutputXml); checkNotSameFile(mInputBigramXml, mOutputXml);
checkNotSameFile(mOutputBinary, mOutputBinaryFormat1);
checkNotSameFile(mOutputBinary, mOutputXml); checkNotSameFile(mOutputBinary, mOutputXml);
checkNotSameFile(mOutputBinaryFormat1, mOutputXml);
} }
private void checkHasExactlyOneInput() { private void checkHasExactlyOneInput() {
@ -90,7 +85,7 @@ public class DictionaryMaker {
} }
private void checkHasAtLeastOneOutput() { private void checkHasAtLeastOneOutput() {
if (null == mOutputBinary && null == mOutputBinaryFormat1 && null == mOutputXml) { if (null == mOutputBinary && null == mOutputXml) {
throw new RuntimeException("No output specified"); throw new RuntimeException("No output specified");
} }
} }
@ -114,13 +109,13 @@ public class DictionaryMaker {
public static String getHelp() { public static String getHelp() {
return "Usage: makedict " return "Usage: makedict "
+ "[-s <unigrams.xml> [-b <bigrams.xml>] [-c <shortcuts_and_whitelist.xml>] " + "[-s <unigrams.xml> [-b <bigrams.xml>] [-c <shortcuts_and_whitelist.xml>] "
+ "| -s <binary input>] [-d <binary output format version 2>] " + "| [-s <binary input>] [-d <binary output>] [-x <xml output>] "
+ "[-d1 <binary output format version 1>] [-x <xml output>] [-2]\n" + "[-1] [-2] [-3]\n"
+ "\n" + "\n"
+ " Converts a source dictionary file to one or several outputs.\n" + " Converts a source dictionary file to one or several outputs.\n"
+ " Source can be an XML file, with an optional XML bigrams file, or a\n" + " Source can be an XML file, with an optional XML bigrams file, or a\n"
+ " binary dictionary file.\n" + " binary dictionary file.\n"
+ " Binary version 1 (Ice Cream Sandwich), 2 (Jelly Bean) and XML outputs\n" + " Binary version 1 (Ice Cream Sandwich), 2 (Jelly Bean), 3 and XML outputs\n"
+ " are supported. All three can be output at the same time, but the same\n" + " are supported. All three can be output at the same time, but the same\n"
+ " output format cannot be specified several times. The behavior is\n" + " output format cannot be specified several times. The behavior is\n"
+ " unspecified if the same file is specified for input and output, or for\n" + " unspecified if the same file is specified for input and output, or for\n"
@ -137,8 +132,8 @@ public class DictionaryMaker {
String inputShortcutXml = null; String inputShortcutXml = null;
String inputBigramXml = null; String inputBigramXml = null;
String outputBinary = null; String outputBinary = null;
String outputBinaryFormat1 = null;
String outputXml = null; String outputXml = null;
int outputBinaryFormatVersion = 2; // the default version is 2.
while (!args.isEmpty()) { while (!args.isEmpty()) {
final String arg = args.get(0); final String arg = args.get(0);
@ -146,6 +141,10 @@ public class DictionaryMaker {
if (arg.charAt(0) == '-') { if (arg.charAt(0) == '-') {
if (OPTION_VERSION_2.equals(arg)) { if (OPTION_VERSION_2.equals(arg)) {
// Do nothing, this is the default // Do nothing, this is the default
} else if (OPTION_VERSION_3.equals(arg)) {
outputBinaryFormatVersion = 3;
} else if (OPTION_VERSION_1.equals(arg)) {
outputBinaryFormatVersion = 1;
} else if (OPTION_HELP.equals(arg)) { } else if (OPTION_HELP.equals(arg)) {
displayHelp(); displayHelp();
} else { } else {
@ -168,8 +167,6 @@ public class DictionaryMaker {
inputBigramXml = filename; inputBigramXml = filename;
} else if (OPTION_OUTPUT_BINARY.equals(arg)) { } else if (OPTION_OUTPUT_BINARY.equals(arg)) {
outputBinary = filename; outputBinary = filename;
} else if (OPTION_OUTPUT_BINARY_FORMAT_VERSION_1.equals(arg)) {
outputBinaryFormat1 = filename;
} else if (OPTION_OUTPUT_XML.equals(arg)) { } else if (OPTION_OUTPUT_XML.equals(arg)) {
outputXml = filename; outputXml = filename;
} else { } else {
@ -196,8 +193,8 @@ public class DictionaryMaker {
mInputShortcutXml = inputShortcutXml; mInputShortcutXml = inputShortcutXml;
mInputBigramXml = inputBigramXml; mInputBigramXml = inputBigramXml;
mOutputBinary = outputBinary; mOutputBinary = outputBinary;
mOutputBinaryFormat1 = outputBinaryFormat1;
mOutputXml = outputXml; mOutputXml = outputXml;
mOutputBinaryFormatVersion = outputBinaryFormatVersion;
checkIntegrity(); checkIntegrity();
} }
} }
@ -294,10 +291,7 @@ public class DictionaryMaker {
throws FileNotFoundException, IOException, UnsupportedFormatException, throws FileNotFoundException, IOException, UnsupportedFormatException,
IllegalArgumentException { IllegalArgumentException {
if (null != args.mOutputBinary) { if (null != args.mOutputBinary) {
writeBinaryDictionary(args.mOutputBinary, dict, 2); writeBinaryDictionary(args.mOutputBinary, dict, args.mOutputBinaryFormatVersion);
}
if (null != args.mOutputBinaryFormat1) {
writeBinaryDictionary(args.mOutputBinaryFormat1, dict, 1);
} }
if (null != args.mOutputXml) { if (null != args.mOutputXml) {
writeXmlDictionary(args.mOutputXml, dict); writeXmlDictionary(args.mOutputXml, dict);