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;
public final Dictionary dictionary;
public final List<IndexBuilder> indexBuilders = new ArrayList<IndexBuilder>();
- public DictionaryBuilder(final String dictInfo, final Language lang0, final Language lang1, final String normalizerRules1, final String normalizerRules2, final Set<String> lang1Stoplist, final Set<String> lang2Stoplist) {
- dictionary = new Dictionary(dictInfo);
+ public DictionaryBuilder(final String dictInfoString, final Language lang0, final Language lang1, final String normalizerRules1, final String normalizerRules2, final Set<String> lang1Stoplist, final Set<String> lang2Stoplist) {
+ dictionary = new Dictionary(dictInfoString);
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));
}
}
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<String,String> 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<String> lang1Stoplist = new LinkedHashSet<String>();
final Set<String> lang2Stoplist = new LinkedHashSet<String>();
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, 0);
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"));
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);
}
private static void fatalError(String string) {
System.err.println(string);
+
+
System.exit(1);
}