aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/dicttool/Android.mk9
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/Compress.java14
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java (renamed from tools/makedict/src/com/android/inputmethod/latin/makedict/DictionaryMaker.java)15
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/Dicttool.java59
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/Info.java9
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/Makedict.java40
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/MakedictLog.java (renamed from tools/makedict/src/com/android/inputmethod/latin/makedict/MakedictLog.java)0
-rw-r--r--tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java (renamed from tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java)4
-rw-r--r--tools/dicttool/tests/com/android/inputmethod/latin/makedict/BinaryDictInputOutputTest.java (renamed from tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java)0
-rwxr-xr-xtools/dicttool/tests/etc/test-dicttool.sh16
-rw-r--r--tools/makedict/Android.mk4
11 files changed, 107 insertions, 63 deletions
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
index 9e8dbe0f8..e9c11acc4 100644
--- a/tools/dicttool/Android.mk
+++ b/tools/dicttool/Android.mk
@@ -16,9 +16,16 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-java-files-under,src)
+MAKEDICT_CORE_SOURCE_DIRECTORY := ../../java/src/com/android/inputmethod/latin/makedict
+
+LOCAL_MAIN_SRC_FILES := $(call all-java-files-under,$(MAKEDICT_CORE_SOURCE_DIRECTORY))
+LOCAL_TOOL_SRC_FILES := $(call all-java-files-under,src)
+LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
+ $(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
+ $(call all-java-files-under,tests)
LOCAL_JAR_MANIFEST := etc/manifest.txt
LOCAL_MODULE := dicttool
+LOCAL_JAVA_LIBRARIES := junit
LOCAL_MODULE_TAGS := eng
include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/Compress.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/Compress.java
index 307f5964c..a76ec50e0 100644
--- a/tools/dicttool/src/android/inputmethod/latin/dicttool/Compress.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/Compress.java
@@ -55,11 +55,10 @@ public class Compress {
return "compress <filename>: Compresses a file using gzip compression";
}
- public int getArity() {
- return 1;
- }
-
public void run() throws IOException {
+ if (mArgs.length < 1) {
+ throw new RuntimeException("Not enough arguments for command " + COMMAND);
+ }
final String inFilename = mArgs[0];
final String outFilename = inFilename + SUFFIX;
final FileInputStream input = new FileInputStream(new File(inFilename));
@@ -79,11 +78,10 @@ public class Compress {
return "uncompress <filename>: Uncompresses a file compressed with gzip compression";
}
- public int getArity() {
- return 1;
- }
-
public void run() throws IOException {
+ if (mArgs.length < 1) {
+ throw new RuntimeException("Not enough arguments for command " + COMMAND);
+ }
final String inFilename = mArgs[0];
final String outFilename = inFilename + SUFFIX;
final FileInputStream input = new FileInputStream(new File(inFilename));
diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/DictionaryMaker.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java
index 5e3921573..9ebd3bbdd 100644
--- a/tools/makedict/src/com/android/inputmethod/latin/makedict/DictionaryMaker.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java
@@ -14,7 +14,12 @@
* the License.
*/
-package com.android.inputmethod.latin.makedict;
+package com.android.inputmethod.latin.dicttool;
+
+import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FusionDictionary;
+import com.android.inputmethod.latin.makedict.MakedictLog;
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import java.io.File;
import java.io.FileInputStream;
@@ -102,7 +107,11 @@ public class DictionaryMaker {
}
private void displayHelp() {
- MakedictLog.i("Usage: makedict "
+ MakedictLog.i(getHelp());
+ }
+
+ public static String getHelp() {
+ return "Usage: makedict "
+ "[-s <unigrams.xml> [-b <bigrams.xml>] [-c <shortcuts.xml>] "
+ "| -s <binary input>] [-d <binary output format version 2>] "
+ "[-d1 <binary output format version 1>] [-x <xml output>] [-2]\n"
@@ -114,7 +123,7 @@ public class DictionaryMaker {
+ " 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"
+ " unspecified if the same file is specified for input and output, or for\n"
- + " several outputs.");
+ + " several outputs.";
}
public Arguments(String[] argsArray) throws IOException {
diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/Dicttool.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/Dicttool.java
index b78be7975..c14ce7b88 100644
--- a/tools/dicttool/src/android/inputmethod/latin/dicttool/Dicttool.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/Dicttool.java
@@ -16,7 +16,6 @@
package com.android.inputmethod.latin.dicttool;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -27,7 +26,6 @@ public class Dicttool {
public void setArgs(String[] args) throws IllegalArgumentException {
mArgs = args;
}
- abstract public int getArity();
abstract public String getHelp();
abstract public void run() throws Exception;
}
@@ -37,6 +35,7 @@ public class Dicttool {
sCommands.put("info", Info.class);
sCommands.put("compress", Compress.Compressor.class);
sCommands.put("uncompress", Compress.Uncompressor.class);
+ sCommands.put("makedict", Makedict.class);
}
private static Command getCommandInstance(final String commandName) {
@@ -62,59 +61,33 @@ public class Dicttool {
return sCommands.containsKey(commandName);
}
- private String mPreviousCommand = null; // local to the getNextCommand function
- private Command getNextCommand(final ArrayList<String> arguments) {
- final String firstArgument = arguments.get(0);
- final String commandName;
- if (isCommand(firstArgument)) {
- commandName = firstArgument;
- arguments.remove(0);
- } else if (isCommand(mPreviousCommand)) {
- commandName = mPreviousCommand;
- } else {
- throw new RuntimeException("Unknown command : " + firstArgument);
+ private Command getCommand(final String[] arguments) {
+ final String commandName = arguments[0];
+ if (!isCommand(commandName)) {
+ throw new RuntimeException("Unknown command : " + commandName);
}
final Command command = getCommandInstance(commandName);
- final int arity = command.getArity();
- if (arguments.size() < arity) {
- throw new RuntimeException("Not enough arguments to command " + commandName);
- }
- final String[] argsArray = new String[arity];
- arguments.subList(0, arity).toArray(argsArray);
- for (int i = 0; i < arity; ++i) {
- // For some reason, ArrayList#removeRange is protected
- arguments.remove(0);
- }
+ final String[] argsArray = Arrays.copyOfRange(arguments, 1, arguments.length);
command.setArgs(argsArray);
- mPreviousCommand = commandName;
return command;
}
- private void execute(final ArrayList<String> arguments) {
- ArrayList<Command> commandsToExecute = new ArrayList<Command>();
- while (!arguments.isEmpty()) {
- commandsToExecute.add(getNextCommand(arguments));
- }
- for (final Command command : commandsToExecute) {
- try {
- command.run();
- } catch (Exception e) {
- System.out.println("Exception while processing command "
- + command.getClass().getSimpleName() + " : " + e);
- return;
- }
+ private void execute(final String[] arguments) {
+ final Command command = getCommand(arguments);
+ try {
+ command.run();
+ } catch (Exception e) {
+ System.out.println("Exception while processing command "
+ + command.getClass().getSimpleName() + " : " + e);
+ return;
}
}
- public static void main(final String[] args) {
- if (0 == args.length) {
+ public static void main(final String[] arguments) {
+ if (0 == arguments.length) {
help();
return;
}
- if (!isCommand(args[0])) throw new RuntimeException("Unknown command : " + args[0]);
-
- final ArrayList<String> arguments = new ArrayList<String>(args.length);
- arguments.addAll(Arrays.asList(args));
new Dicttool().execute(arguments);
}
}
diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/Info.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/Info.java
index cb032dd3b..e59261706 100644
--- a/tools/dicttool/src/android/inputmethod/latin/dicttool/Info.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/Info.java
@@ -17,6 +17,8 @@
package com.android.inputmethod.latin.dicttool;
public class Info extends Dicttool.Command {
+ public static final String COMMAND = "info";
+
public Info() {
}
@@ -24,12 +26,11 @@ public class Info extends Dicttool.Command {
return "info <filename>: prints various information about a dictionary file";
}
- public int getArity() {
- return 1;
- }
-
public void run() {
// TODO: implement this
+ if (mArgs.length < 1) {
+ throw new RuntimeException("Not enough arguments for command " + COMMAND);
+ }
System.out.println("Not implemented yet");
}
}
diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/Makedict.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/Makedict.java
new file mode 100644
index 000000000..c004cfbe4
--- /dev/null
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/Makedict.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin.dicttool;
+
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.xml.sax.SAXException;
+
+public class Makedict extends Dicttool.Command {
+ public static final String COMMAND = "makedict";
+
+ public Makedict() {
+ }
+
+ public String getHelp() {
+ return DictionaryMaker.Arguments.getHelp();
+ }
+
+ public void run() throws FileNotFoundException, IOException, ParserConfigurationException,
+ SAXException, UnsupportedFormatException {
+ DictionaryMaker.main(mArgs);
+ }
+}
diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/MakedictLog.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/MakedictLog.java
index 7eccff2b4..7eccff2b4 100644
--- a/tools/makedict/src/com/android/inputmethod/latin/makedict/MakedictLog.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/MakedictLog.java
diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
index 52f124dfb..8e2e73505 100644
--- a/tools/makedict/src/com/android/inputmethod/latin/makedict/XmlDictInputOutput.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
@@ -14,11 +14,13 @@
* the License.
*/
-package com.android.inputmethod.latin.makedict;
+package com.android.inputmethod.latin.dicttool;
+import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.makedict.Word;
import java.io.IOException;
import java.io.InputStream;
diff --git a/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/BinaryDictInputOutputTest.java
index 24042f120..24042f120 100644
--- a/tools/makedict/tests/com/android/inputmethod/latin/BinaryDictInputOutputTest.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/BinaryDictInputOutputTest.java
diff --git a/tools/dicttool/tests/etc/test-dicttool.sh b/tools/dicttool/tests/etc/test-dicttool.sh
new file mode 100755
index 000000000..8834611cd
--- /dev/null
+++ b/tools/dicttool/tests/etc/test-dicttool.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Copyright 2012, The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+java -classpath ${ANDROID_HOST_OUT}/framework/junit.jar:${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES/dicttool_intermediates/classes junit.textui.TestRunner com.android.inputmethod.latin.makedict.BinaryDictInputOutputTest
diff --git a/tools/makedict/Android.mk b/tools/makedict/Android.mk
index 7b5dee2ce..cac3a831c 100644
--- a/tools/makedict/Android.mk
+++ b/tools/makedict/Android.mk
@@ -20,9 +20,7 @@ MAKEDICT_CORE_SOURCE_DIRECTORY := ../../java/src/com/android/inputmethod/latin/m
LOCAL_MAIN_SRC_FILES := $(call all-java-files-under,$(MAKEDICT_CORE_SOURCE_DIRECTORY))
LOCAL_TOOL_SRC_FILES := $(call all-java-files-under,src)
-LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
- $(filter-out $(addprefix %, $(LOCAL_TOOL_SRC_FILES)), $(LOCAL_MAIN_SRC_FILES))
-LOCAL_SRC_FILES += $(call all-java-files-under,tests)
+LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES)
LOCAL_JAR_MANIFEST := etc/manifest.txt
LOCAL_MODULE := makedict
LOCAL_JAVA_LIBRARIES := junit