package com.hughes.android.dictionary.engine;
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.RandomAccessFile;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.LinkedHashMap;
+import java.util.Map;
import junit.framework.TestCase;
+import com.hughes.android.dictionary.parser.enwiktionary.EnWiktionaryLangs;
+
public class DictionaryBuilderMain extends TestCase {
- static class Lang {
- final String nameRegex;
- final String code;
- public Lang(String nameRegex, String code) {
- this.nameRegex = nameRegex;
- this.code = code;
- }
- }
-
-
+ static final String INPUTS = "data/inputs/";
+ static final String STOPLISTS = "data/inputs/stoplists/";
+ static final String OUTPUTS = "data/outputs/";
+
public static void main(final String[] args) throws Exception {
+
+ // Builds all the dictionaries it can, outputs list to a text file.
+
+ final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(EnWiktionaryLangs.isoCodeToWikiName);
+ isoToWikiName.remove("EN");
+ isoToWikiName.remove("DE");
+
+ final Map<String,String> isoToDedication = new LinkedHashMap<String, String>();
+ isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
+ isoToDedication.put("HR", "Croatian dictionary dedicated to Ines Viskic and Miro Kresonja.");
+ isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
+ // German handled in file.
+ isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
+ isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe! Ti amo!");
+ isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
+ isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
+ isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
+ isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
+ isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
+ isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
+ isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
- Lang[] langs1 = new Lang[] {
- new Lang("^English$", "EN"),
- //new Lang("^German$", "DE"),
- };
- Lang[] langs2 = new Lang[] {
- new Lang("^Italian$", "IT"),
- new Lang("^German$", "DE"),
- new Lang("^Afrikaans$", "AF"),
- new Lang("^Armenian$", "HY"),
- new Lang("^Arabic$", "AR"),
- new Lang("^Chinese$|^Mandarin$", "ZH"),
- new Lang("^Croation$", "HR"),
- new Lang("^Czech$", "CS"),
- new Lang("^Dutch$", "NL"),
- new Lang("^English$", "EN"),
- new Lang("^Finnish$", "FI"),
- new Lang("^French$", "FR"),
- new Lang("^Greek$", "EL"),
- new Lang("^Hebrew$", "HE"),
- new Lang("^Hindi$", "HI"),
- new Lang("^Icelandic$", "IS"),
- new Lang("^Irish$", "GA"),
- new Lang("^Japanese$", "JA"),
- new Lang("^Korean$", "KO"),
- new Lang("^Kurdish$", "KU"),
- new Lang("^Lithuanian$", "LT"),
- new Lang("^Malay$", "MS"),
- new Lang("^Maori$", "MI"),
- new Lang("^Mongolian$", "MN"),
- new Lang("^Norwegian$", "NO"),
- new Lang("^Persian$", "FA"),
- new Lang("^Portuguese$", "PT"),
- new Lang("^Romanian$", "RO"),
- new Lang("^Russian$", "RU"),
- new Lang("^Sanskrit$", "SA"),
- new Lang("^Serbian$", "SR"),
- new Lang("^Somali$", "SO"),
- new Lang("^Spanish$", "ES"),
- new Lang("^Sudanese$", "SU"),
- new Lang("^Swedish$", "SV"),
- new Lang("^Tajik$", "TG"),
- new Lang("^Thai$", "TH"),
- new Lang("^Tibetan$", "BO"),
- new Lang("^Turkish$", "TR"),
- new Lang("^Ukranian$", "UK"),
- new Lang("^Vietnamese$", "VI"),
- new Lang("^Welsh$", "CY"),
- new Lang("^Yiddish$", "YI"),
- new Lang("^Zulu$", "ZU"),
- };
+ final Map<String,String> isoToStoplist = new LinkedHashMap<String, String>();
+ isoToStoplist.put("DE", "de.txt");
+ isoToStoplist.put("EN", "en.txt");
+ isoToStoplist.put("ES", "es.txt");
+ isoToStoplist.put("IT", "it.txt");
+ isoToStoplist.put("FR", "fr.txt");
+
+ final Map<String,String> isoToRegex = new LinkedHashMap<String, String>();
+ // HACK: The missing "e" prevents a full match, causing "Cantonese" to be appended to the entries.
+ isoToRegex.put("ZH", "Chinese|Mandarin|Cantones");
- for (final Lang lang1 : langs1) {
- for (final Lang lang2 : langs2) {
- if (lang1.nameRegex.equals(lang2.nameRegex)) {
- continue;
- }
+// isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
+ //isoToWikiName.clear();
+ boolean go = true;
+ for (final String foreignIso : isoToWikiName.keySet()) {
+ if (foreignIso.equals("SK")) {
+ go = true;
+ }
+ if (!go) {
+ continue;
+ }
+
+ final String dictFile = String.format("%s/EN-%s_enwiktionary.quickdic", OUTPUTS, foreignIso);
+ System.out.println("building dictFile: " + dictFile);
- int enIndex = -1;
- if (lang2.code.equals("EN")) {
- enIndex = 2;
+ if (!isoToStoplist.containsKey(foreignIso)) {
+ isoToStoplist.put(foreignIso, "empty.txt");
}
- if (lang1.code.equals("EN")) {
- enIndex = 1;
+ if (!isoToDedication.containsKey(foreignIso)) {
+ isoToDedication.put(foreignIso, "");
}
-
- final String dictFile = String.format("dictOutputs/%s-%s_enwiktionary.quickdic", lang1.code, lang2.code);
- System.out.println("building dictFile: " + dictFile);
+ if (!isoToRegex.containsKey(foreignIso)) {
+ isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
+ }
+
DictionaryBuilder.main(new String[] {
String.format("--dictOut=%s", dictFile),
- String.format("--lang1=%s", lang1.code),
- String.format("--lang2=%s", lang2.code),
- String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.code, lang2.code),
+ String.format("--lang1=EN"),
+ String.format("--lang2=%s", foreignIso),
+ String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
+ String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
+ String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary. %s", foreignIso, isoToDedication.get(foreignIso)),
- "--input1=dictInputs/enwiktionary-20110205-pages-articles.xml",
- "--input1Name=enwiktionary",
- "--input1Format=enwiktionary",
- String.format("--input1TranslationPattern1=%s", lang1.nameRegex),
- String.format("--input1TranslationPattern2=%s", lang2.nameRegex),
- String.format("--input1EnIndex=%d", enIndex),
- });
-
- // Print the entries for diffing.
- final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
- final Dictionary dict = new Dictionary(raf);
- final PrintWriter textOut = new PrintWriter(new File(dictFile + ".txt"));
- final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
- Collections.sort(sorted);
- for (final PairEntry pairEntry : sorted) {
- textOut.println(pairEntry.getRawText(false));
- }
- textOut.close();
- raf.close();
-
- } // langs2
- } // langs1
+ "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
+ "--input2Name=enwiktionary." + foreignIso,
+ "--input2Format=enwiktionary",
+ "--input2LangPattern=" + isoToRegex.get(foreignIso),
+ "--input2LangCodePattern=" + foreignIso.toLowerCase(),
+ "--input2EnIndex=1",
- DictionaryBuilder.main(new String[] {
- "--dictOut=dictOutputs/DE-EN_chemnitz.quickdic",
- "--lang1=DE",
- "--lang2=EN",
- "--dictInfo=@dictInputs/de-en_chemnitz.info",
+ "--input3=" + INPUTS + "enWikiSplit/EN.data",
+ "--input3Name=enwiktionary.english",
+ "--input3Format=enwiktionary",
+ "--input3LangPattern=" + isoToRegex.get(foreignIso),
+ "--input3LangCodePattern=" + foreignIso.toLowerCase(),
+ "--input3EnIndex=1",
- "--input1=dictInputs/de-en_chemnitz.txt",
- "--input1Name=chemnitz",
- "--input1Charset=UTF8",
- "--input1Format=chemnitz",
- });
+ });
+
+ } // foreignIso
+ final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.%s.quickdic", OUTPUTS);
DictionaryBuilder.main(new String[] {
- "--dictOut=dictOutputs/de-en_all.quickdic",
+ "--dictOut=" + dictFile,
"--lang1=DE",
"--lang2=EN",
- "--dictInfo=@dictInputs/de-en_all.info",
+ String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
+ String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
+ "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
- "--input2=dictInputs/de-en_chemnitz.txt",
- "--input2Name=dictcc",
- "--input2Charset=UTF8",
- "--input2Format=chemnitz",
-
- "--input3=dictInputs/de-en_dictcc.txt",
- "--input3Name=dictcc",
- "--input3Charset=UTF8",
- "--input3Format=dictcc",
+ "--input4=" + INPUTS + "de-en_chemnitz.txt",
+ "--input4Name=chemnitz",
+ "--input4Charset=UTF8",
+ "--input4Format=chemnitz",
- "--input1=dictInputs/enwiktionary-20101015-pages-articles",
- "--input1Name=enwiktionary",
- "--input1Format=enwiktionary",
- "--input1TranslationPattern1=^German$",
- "--input1TranslationPattern2=^English$",
- "--input1EnIndex=2",
+ "--input2=" + INPUTS + "enWikiSplit/DE.data",
+ "--input2Name=enwiktionary.DE",
+ "--input2Format=enwiktionary",
+ "--input2LangPattern=German",
+ "--input2LangCodePattern=de",
+ "--input2EnIndex=2",
+ "--input3=" + INPUTS + "enWikiSplit/EN.data",
+ "--input3Name=enwiktionary.english",
+ "--input3Format=enwiktionary",
+ "--input3LangPattern=German",
+ "--input3LangCodePattern=de",
+ "--input3EnIndex=2",
});
-
+
}
-
+
}