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.Arrays;
18 import java.util.LinkedHashMap;
19 import java.util.LinkedHashSet;
20 import java.util.List;
24 import junit.framework.TestCase;
26 import com.hughes.android.dictionary.parser.wiktionary.EnTranslationToTranslationParser;
27 import com.hughes.android.dictionary.parser.wiktionary.WiktionaryLangs;
29 public class DictionaryBuilderMain extends TestCase {
31 static final String INPUTS = "data/inputs/";
32 static final String STOPLISTS = "data/inputs/stoplists/";
33 static final String OUTPUTS = "data/outputs/";
35 public static <E> void main(final String[] args) throws Exception {
37 // Builds all the dictionaries it can, outputs list to a text file.
39 final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(WiktionaryLangs.isoCodeToWikiName);
40 isoToWikiName.remove("EN");
41 isoToWikiName.remove("DE");
43 final Map<String,String> isoToDedication = new LinkedHashMap<String, String>();
44 isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
45 isoToDedication.put("HR", "Croatian dictionary dedicated to Ines Viskic and Miro Kresonja.");
46 isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
47 // German handled in file.
48 isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
49 isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe! Ti amo!");
50 isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
51 isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
52 isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
53 isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
54 isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
55 isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
56 isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
58 final Map<String,String> isoToStoplist = new LinkedHashMap<String, String>();
59 isoToStoplist.put("DE", "de.txt");
60 isoToStoplist.put("EN", "en.txt");
61 isoToStoplist.put("ES", "es.txt");
62 isoToStoplist.put("IT", "it.txt");
63 isoToStoplist.put("FR", "fr.txt");
65 final Map<String,String> isoToRegex = new LinkedHashMap<String, String>();
66 // HACK: The missing "e" prevents a full match, causing "Cantonese" to be appended to the entries.
67 isoToRegex.put("ZH", "Chinese|Mandarin|Cantones");
70 // Build the non EN ones.
72 final String[][] nonEnPairs = new String[][] {
82 {"DE", "CA" }, // Catalan
83 {"DE", "CS" }, // Czech
84 {"DE", "EO" }, // Esperanto
87 {"DE", "HU" }, // Hungarian
90 {"DE", "LA" }, // Latin
91 {"DE", "PL" }, // Polish
93 {"DE", "SV" }, // Swedish
97 {"FR", "BG" }, // Bulgarian
98 {"FR", "CS" }, // Czech
104 {"FR", "NL" }, // Dutch
109 {"IT", "EL" }, // Greek
114 {"IT", "LA" }, // Latin
115 {"IT", "LV" }, // Latvian
140 final Set<List<String>> done = new LinkedHashSet<List<String>>();
141 for (final String[] pair : nonEnPairs) {
143 final List<String> pairList = Arrays.asList(pair);
144 if (done.contains(pairList)) {
149 final String lang1 = pair[0];
150 final String lang2 = pair[1];
152 final String dictFile = String.format("%s/%s-%s_enwiktionary_BETA.quickdic",
153 OUTPUTS, lang1, lang2);
154 System.out.println("building dictFile: " + dictFile);
156 if (!isoToStoplist.containsKey(lang1)) {
157 isoToStoplist.put(lang1, "empty.txt");
159 if (!isoToStoplist.containsKey(lang2)) {
160 isoToStoplist.put(lang2, "empty.txt");
163 DictionaryBuilder.main(new String[] {
164 String.format("--dictOut=%s", dictFile),
165 String.format("--lang1=%s", lang1),
166 String.format("--lang2=%s", lang2),
167 String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get(lang1)),
168 String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(lang2)),
169 String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary.", lang1, lang2),
171 String.format("--input2=%swikiSplit/en/EN.data", INPUTS),
172 String.format("--input2Name=BETA!enwiktionary.%s-%s", lang1, lang2),
173 String.format("--input2Format=%s", EnTranslationToTranslationParser.NAME),
174 String.format("--input2LangPattern1=%s", lang1),
175 String.format("--input2LangPattern2=%s", lang2),
183 // Now build the EN ones.
185 // isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
186 //isoToWikiName.clear();
188 for (final String foreignIso : isoToWikiName.keySet()) {
189 if (foreignIso.equals("GD")) {
196 final String dictFile = String.format("%s/EN-%s_enwiktionary.quickdic", OUTPUTS, foreignIso);
197 System.out.println("building dictFile: " + dictFile);
199 if (!isoToStoplist.containsKey(foreignIso)) {
200 isoToStoplist.put(foreignIso, "empty.txt");
202 if (!isoToDedication.containsKey(foreignIso)) {
203 isoToDedication.put(foreignIso, "");
205 if (!isoToRegex.containsKey(foreignIso)) {
206 isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
209 DictionaryBuilder.main(new String[] {
210 String.format("--dictOut=%s", dictFile),
211 String.format("--lang1=EN"),
212 String.format("--lang2=%s", foreignIso),
213 String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
214 String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
215 String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary.\n\n%s", foreignIso, isoToDedication.get(foreignIso)),
217 "--input2=" + INPUTS + "wikiSplit/en/" + foreignIso + ".data",
218 "--input2Name=enwiktionary." + foreignIso,
219 "--input2Format=enwiktionary",
220 "--input2WiktionaryType=EnForeign",
221 "--input2LangPattern=" + isoToRegex.get(foreignIso),
222 "--input2LangCodePattern=" + foreignIso.toLowerCase(),
225 "--input3=" + INPUTS + "wikiSplit/en/EN.data",
226 "--input3Name=enwiktionary.english",
227 "--input3Format=enwiktionary",
228 "--input3WiktionaryType=EnToTranslation",
229 "--input3LangPattern=" + isoToRegex.get(foreignIso),
230 "--input3LangCodePattern=" + foreignIso.toLowerCase(),
237 // Now special case German-English.
239 final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.quickdic", OUTPUTS);
240 DictionaryBuilder.main(new String[] {
241 "--dictOut=" + dictFile,
244 String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
245 String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
246 "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
248 "--input4=" + INPUTS + "de-en_chemnitz.txt",
249 "--input4Name=chemnitz",
250 "--input4Charset=UTF8",
251 "--input4Format=chemnitz",
253 "--input2=" + INPUTS + "wikiSplit/en/DE.data",
254 "--input2Name=enwiktionary.DE",
255 "--input2Format=enwiktionary",
256 "--input2WiktionaryType=EnForeign",
257 "--input2LangPattern=German",
258 "--input2LangCodePattern=de",
261 "--input3=" + INPUTS + "wikiSplit/en/EN.data",
262 "--input3Name=enwiktionary.english",
263 "--input3Format=enwiktionary",
264 "--input3WiktionaryType=EnToTranslation",
265 "--input3LangPattern=German",
266 "--input3LangCodePattern=de",