1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 package com.hughes.android.dictionary.engine;
17 import java.util.LinkedHashMap;
20 import junit.framework.TestCase;
22 import com.hughes.android.dictionary.parser.enwiktionary.EnWiktionaryLangs;
24 public class DictionaryBuilderMain extends TestCase {
26 static final String INPUTS = "data/inputs/";
27 static final String STOPLISTS = "data/inputs/stoplists/";
28 static final String OUTPUTS = "data/outputs/";
30 public static void main(final String[] args) throws Exception {
32 // Builds all the dictionaries it can, outputs list to a text file.
34 final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(EnWiktionaryLangs.isoCodeToWikiName);
35 isoToWikiName.remove("EN");
36 isoToWikiName.remove("DE");
38 final Map<String,String> isoToDedication = new LinkedHashMap<String, String>();
39 isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
40 isoToDedication.put("HR", "Croatian dictionary dedicated to Ines Viskic and Miro Kresonja.");
41 isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
42 // German handled in file.
43 isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
44 isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe! Ti amo!");
45 isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
46 isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
47 isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
48 isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
49 isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
50 isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
51 isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
53 final Map<String,String> isoToStoplist = new LinkedHashMap<String, String>();
54 isoToStoplist.put("DE", "de.txt");
55 isoToStoplist.put("EN", "en.txt");
56 isoToStoplist.put("ES", "es.txt");
57 isoToStoplist.put("IT", "it.txt");
58 isoToStoplist.put("FR", "fr.txt");
60 final Map<String,String> isoToRegex = new LinkedHashMap<String, String>();
61 // HACK: The missing "e" prevents a full match, causing "Cantonese" to be appended to the entries.
62 isoToRegex.put("ZH", "Chinese|Mandarin|Cantones");
64 // isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
65 //isoToWikiName.clear();
67 for (final String foreignIso : isoToWikiName.keySet()) {
68 if (foreignIso.equals("SK")) {
75 final String dictFile = String.format("%s/EN-%s_enwiktionary.quickdic", OUTPUTS, foreignIso);
76 System.out.println("building dictFile: " + dictFile);
78 if (!isoToStoplist.containsKey(foreignIso)) {
79 isoToStoplist.put(foreignIso, "empty.txt");
81 if (!isoToDedication.containsKey(foreignIso)) {
82 isoToDedication.put(foreignIso, "");
84 if (!isoToRegex.containsKey(foreignIso)) {
85 isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
88 DictionaryBuilder.main(new String[] {
89 String.format("--dictOut=%s", dictFile),
90 String.format("--lang1=EN"),
91 String.format("--lang2=%s", foreignIso),
92 String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
93 String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
94 String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary. %s", foreignIso, isoToDedication.get(foreignIso)),
96 "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
97 "--input2Name=enwiktionary." + foreignIso,
98 "--input2Format=enwiktionary",
99 "--input2LangPattern=" + isoToRegex.get(foreignIso),
100 "--input2LangCodePattern=" + foreignIso.toLowerCase(),
103 "--input3=" + INPUTS + "enWikiSplit/EN.data",
104 "--input3Name=enwiktionary.english",
105 "--input3Format=enwiktionary",
106 "--input3LangPattern=" + isoToRegex.get(foreignIso),
107 "--input3LangCodePattern=" + foreignIso.toLowerCase(),
114 final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.%s.quickdic", OUTPUTS);
115 DictionaryBuilder.main(new String[] {
116 "--dictOut=" + dictFile,
119 String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
120 String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
121 "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
123 "--input4=" + INPUTS + "de-en_chemnitz.txt",
124 "--input4Name=chemnitz",
125 "--input4Charset=UTF8",
126 "--input4Format=chemnitz",
128 "--input2=" + INPUTS + "enWikiSplit/DE.data",
129 "--input2Name=enwiktionary.DE",
130 "--input2Format=enwiktionary",
131 "--input2LangPattern=German",
132 "--input2LangCodePattern=de",
135 "--input3=" + INPUTS + "enWikiSplit/EN.data",
136 "--input3Name=enwiktionary.english",
137 "--input3Format=enwiktionary",
138 "--input3LangPattern=German",
139 "--input3LangCodePattern=de",