X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FDictionaryBuilderMain.java;h=db5caa864562fc76322372fd2d5a7945090aa76a;hb=b3dd51971927861bdaeab3ea1569006c07653873;hp=3479ec70bcb8d288d1bfba4e4f910ac04597f2fc;hpb=5a79ed5f458a5c469d4b5fa81f25e83baabad57c;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java b/src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java index 3479ec7..db5caa8 100644 --- a/src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java +++ b/src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java @@ -18,8 +18,11 @@ import java.io.File; import java.io.PrintWriter; import java.io.RandomAccessFile; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import junit.framework.TestCase; @@ -28,115 +31,83 @@ public class DictionaryBuilderMain extends TestCase { static final String INPUTS = "../DictionaryData/inputs/"; static final String STOPLISTS = "../DictionaryData/inputs/stoplists/"; static final String OUTPUTS = "../DictionaryData/outputs/"; - - static class Lang { - final String nameRegex; - final String isoCode; - final String wikiSplit; - final String stoplistFile; - public Lang(String nameRegex, String code, final String wikiSplit, final String stoplistFile) { - this.nameRegex = nameRegex; - this.isoCode = code; - this.wikiSplit = wikiSplit; - this.stoplistFile = stoplistFile; - } - } - - + public static void main(final String[] args) throws Exception { - - Lang[] langs1 = new Lang[] { - new Lang("^English$", "EN", null, "en.txt"), - }; - Lang[] langs2 = new Lang[] { - //new Lang("^.*Italian.*$", "IT", "italian.data", "it.txt"), - new Lang("^.*French.*$", "FR", "french.data", "empty.txt"), - new Lang("^.*Spanish.*$", "ES", "spanish.data", "empty.txt"), - new Lang("^.*Greek.*$", "EL", "greek.data", "empty.txt"), - new Lang("^.*Japanese.*$", "JA", "japanese.data", "empty.txt"), - new Lang("^.*Chinese.*$|^.*Mandarin.*$", "ZH", "mandarin.data", "empty.txt"), - /* - new Lang("^German$", "DE"), - new Lang("^Afrikaans$", "AF"), - new Lang("^Armenian$", "HY"), - new Lang("^Arabic$", "AR"), - new Lang("^Croation$", "HR"), - new Lang("^Czech$", "CS"), - new Lang("^Dutch$", "NL"), - new Lang("^English$", "EN"), - new Lang("^Finnish$", "FI"), - new Lang("^Hebrew$", "HE"), - new Lang("^Hindi$", "HI"), - new Lang("^Icelandic$", "IS"), - new Lang("^Irish$", "GA"), - 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("^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"),*/ - }; - for (final Lang lang1 : langs1) { - for (final Lang lang2 : langs2) { - if (lang1.nameRegex.equals(lang2.nameRegex)) { - continue; - } + final Map isoToWikiName = new LinkedHashMap(Language.isoCodeToWikiName); + isoToWikiName.remove("EN"); + isoToWikiName.remove("DE"); + + final Map isoToDedication = new LinkedHashMap(); + isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn."); + isoToDedication.put("HR", "Croation 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!"); + + final Map isoToStoplist = new LinkedHashMap(); + 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 isoToRegex = new LinkedHashMap(); + isoToRegex.put("ZH", "Chinese|Mandarin|Cantonese"); + +// isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI")); + boolean go = true; + isoToWikiName.clear(); + for (final String foreignIso : isoToWikiName.keySet()) { + if (foreignIso.equals("SV")) { + go = true; + } + if (!go) { + continue; + } + + final String dictFile = String.format(OUTPUTS + "/EN-%s_enwiktionary.quickdic", foreignIso); + System.out.println("building dictFile: " + dictFile); - int enIndex = -1; - Lang nonEnglish = null; - if (lang2.isoCode.equals("EN")) { - enIndex = 2; - nonEnglish = lang1; + if (!isoToStoplist.containsKey(foreignIso)) { + isoToStoplist.put(foreignIso, "empty.txt"); } - if (lang1.isoCode.equals("EN")) { - enIndex = 1; - nonEnglish = lang2; + if (!isoToDedication.containsKey(foreignIso)) { + isoToDedication.put(foreignIso, ""); } - assert nonEnglish != null; - - final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode); - 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.isoCode), - String.format("--lang2=%s", lang2.isoCode), - String.format("--lang1Stoplist=%s", STOPLISTS + lang1.stoplistFile), - String.format("--lang2Stoplist=%s", STOPLISTS + lang2.stoplistFile), - String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode), - - "--input2=" + INPUTS + "enWikiSplit/" + nonEnglish.wikiSplit, - "--input2Name=enwiktionary." + nonEnglish.wikiSplit, + 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)), + + "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data", + "--input2Name=enwiktionary." + foreignIso, "--input2Format=enwiktionary", - "--input2LangPattern=" + nonEnglish.nameRegex, - "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(), - "--input2EnIndex=" + enIndex, + "--input2LangPattern=" + isoToRegex.get(foreignIso), + "--input2LangCodePattern=" + foreignIso.toLowerCase(), + "--input2EnIndex=1", - "--input3=" + INPUTS + "enWikiSplit/english.data", + "--input3=" + INPUTS + "enWikiSplit/EN.data", "--input3Name=enwiktionary.english", "--input3Format=enwiktionary", - "--input3LangPattern=" + nonEnglish.nameRegex, - "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(), - "--input3EnIndex=" + enIndex, + "--input3LangPattern=" + isoToRegex.get(foreignIso), + "--input3LangCodePattern=" + foreignIso.toLowerCase(), + "--input3EnIndex=1", }); @@ -152,38 +123,35 @@ public class DictionaryBuilderMain extends TestCase { textOut.close(); raf.close(); - } // langs2 - } // langs1 + } // foreignIso DictionaryBuilder.main(new String[] { - "--dictOut=" + OUTPUTS + "DE-EN_chemnitz.quickdic", + "--dictOut=" + OUTPUTS + "DE-EN_chemnitz_enwiktionary.quickdic", "--lang1=DE", "--lang2=EN", - "--dictInfo=@" + INPUTS + "de-en_chemnitz.info", - - "--input1=" + INPUTS + "de-en_chemnitz.txt", - "--input1Name=chemnitz", - "--input1Charset=UTF8", - "--input1Format=chemnitz", - }); - - DictionaryBuilder.main(new String[] { - "--dictOut=" + OUTPUTS + "de-en_all.quickdic", - "--lang1=DE", - "--lang2=EN", - "--dictInfo=@" + INPUTS + "de-en_all.info", - - "--input2=" + INPUTS + "de-en_chemnitz.txt", - "--input2Name=dictcc", - "--input2Charset=UTF8", - "--input2Format=chemnitz", - - "--input3=" + INPUTS + "/NONFREE/de-en_dictcc.txt", - "--input3Name=dictcc", - "--input3Charset=UTF8", - "--input3Format=dictcc", + String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"), + String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"), + "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info", + + "--input4=" + INPUTS + "de-en_chemnitz.txt", + "--input4Name=chemnitz", + "--input4Charset=UTF8", + "--input4Format=chemnitz", + + "--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", - // TODO: wiktionary }); }