X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FDictionaryBuilder.java;h=519663774bc9242c5708d498a725f4f1bda0a672;hb=e2eb68726dc1efce8d833502c211e445bfc2230b;hp=a3cc7c02cd5b7354a7d23b928eda7ae895cd66a2;hpb=52123581b0c4aa46298b9d6cbc4697accffc1cc7;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/engine/DictionaryBuilder.java b/src/com/hughes/android/dictionary/engine/DictionaryBuilder.java index a3cc7c0..5196637 100644 --- a/src/com/hughes/android/dictionary/engine/DictionaryBuilder.java +++ b/src/com/hughes/android/dictionary/engine/DictionaryBuilder.java @@ -20,6 +20,7 @@ import java.io.PrintStream; import java.io.RandomAccessFile; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -43,8 +44,8 @@ public class DictionaryBuilder { public DictionaryBuilder(final String dictInfo, final Language lang0, final Language lang1, final String normalizerRules1, final String normalizerRules2, final Set lang1Stoplist, final Set lang2Stoplist) { dictionary = new Dictionary(dictInfo); - indexBuilders.add(new IndexBuilder(this, lang0.getSymbol(), lang0.getSymbol() + "->" + lang1.getSymbol(), lang0, normalizerRules1, lang1Stoplist, false)); - indexBuilders.add(new IndexBuilder(this, lang1.getSymbol(), lang1.getSymbol() + "->" + lang0.getSymbol(), lang1, normalizerRules2, lang2Stoplist, true)); + indexBuilders.add(new IndexBuilder(this, lang0.getIsoCode(), lang0.getIsoCode() + "->" + lang1.getIsoCode(), lang0, normalizerRules1, lang1Stoplist, false)); + indexBuilders.add(new IndexBuilder(this, lang1.getIsoCode(), lang1.getIsoCode() + "->" + lang0.getIsoCode(), lang1, normalizerRules2, lang2Stoplist, true)); } void build() { @@ -55,13 +56,18 @@ public class DictionaryBuilder { } public static void main(final String[] args) throws IOException, ParserConfigurationException, SAXException { + System.out.println("Running with arguments:"); + for (final String arg : args) { + System.out.println(arg); + } + final Map keyValueArgs = Args.keyValueArgs(args); - final Language lang1 = Language.lookup(keyValueArgs.remove("lang1")); - final Language lang2 = Language.lookup(keyValueArgs.remove("lang2")); - if (lang1 == null || lang2 == null) { + if (!keyValueArgs.containsKey("lang1") || !keyValueArgs.containsKey("lang2")) { fatalError("--lang1= and --lang2= must both be specified."); } + final Language lang1 = Language.lookup(keyValueArgs.remove("lang1")); + final Language lang2 = Language.lookup(keyValueArgs.remove("lang2")); final Set lang1Stoplist = new LinkedHashSet(); final Set lang2Stoplist = new LinkedHashSet(); @@ -122,14 +128,16 @@ public class DictionaryBuilder { fatalError("Must specify human readable name for: " + prefix + "Name"); } - final EntrySource entrySource = new EntrySource(dictionaryBuilder.dictionary.sources.size(), inputName, dictionaryBuilder.dictionary.pairEntries.size()); + final EntrySource entrySource = new EntrySource(dictionaryBuilder.dictionary.sources.size(), inputName); System.out.println(""); String inputFormat = keyValueArgs.remove(prefix + "Format"); - if ("dictcc".equals(inputFormat)) { - new DictFileParser(charset, false, DictFileParser.TAB, null, dictionaryBuilder, dictionaryBuilder.indexBuilders.toArray(new IndexBuilder[0]), null).parseFile(file); + if ("tab_separated".equals(inputFormat)) { + final boolean flipColumns = "true".equals(keyValueArgs.remove(prefix + "FlipColumns")); + new DictFileParser(charset, flipColumns, DictFileParser.TAB, null, dictionaryBuilder, dictionaryBuilder.indexBuilders.toArray(new IndexBuilder[0]), null).parseFile(file, entrySource); } else if ("chemnitz".equals(inputFormat)) { - new DictFileParser(charset, false, DictFileParser.DOUBLE_COLON, DictFileParser.PIPE, dictionaryBuilder, dictionaryBuilder.indexBuilders.toArray(new IndexBuilder[0]), null).parseFile(file); + final boolean flipColumns = "true".equals(keyValueArgs.remove(prefix + "FlipColumns")); + new DictFileParser(charset, flipColumns, DictFileParser.DOUBLE_COLON, DictFileParser.PIPE, dictionaryBuilder, dictionaryBuilder.indexBuilders.toArray(new IndexBuilder[0]), null).parseFile(file, entrySource); } else if ("enwiktionary".equals(inputFormat)) { final Pattern langPattern = Pattern.compile(keyValueArgs.remove(prefix + "LangPattern"), Pattern.CASE_INSENSITIVE); final Pattern langCodePattern = Pattern.compile(keyValueArgs.remove(prefix + "LangCodePattern")); @@ -143,7 +151,7 @@ public class DictionaryBuilder { fatalError("Must be 1 or 2: " + prefix + "EnIndex"); } new EnWiktionaryXmlParser(dictionaryBuilder.indexBuilders.get(enIndex), dictionaryBuilder.indexBuilders.get(1-enIndex), - langPattern, langCodePattern, enIndex != 0).parse(file, Integer.parseInt(pageLimit)); + langPattern, langCodePattern, enIndex != 0).parse(file, entrySource, Integer.parseInt(pageLimit)); } else { fatalError("Invalid or missing input format: " + inputFormat); } @@ -176,6 +184,8 @@ public class DictionaryBuilder { private static void fatalError(String string) { System.err.println(string); + + System.exit(1); }