]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
DictionaryBuilder prints sortable langs, JP->JA fix.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / DictionaryBuilderMain.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.util.Arrays;
18 import java.util.LinkedHashMap;
19 import java.util.LinkedHashSet;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23
24 import junit.framework.TestCase;
25
26 import com.hughes.android.dictionary.parser.wiktionary.EnTranslationToTranslationParser;
27 import com.hughes.android.dictionary.parser.wiktionary.WiktionaryLangs;
28
29 public class DictionaryBuilderMain extends TestCase {
30   
31   static final String INPUTS = "data/inputs/";
32   static final String STOPLISTS = "data/inputs/stoplists/";
33   static final String OUTPUTS = "data/outputs/";  
34     
35   public static <E> void main(final String[] args) throws Exception {
36     
37     // Builds all the dictionaries it can, outputs list to a text file.
38     
39     final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(WiktionaryLangs.isoCodeToWikiName);
40     isoToWikiName.remove("EN");
41     isoToWikiName.remove("DE");
42
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!");
57
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");
64
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");
68     
69     
70     // Build the non EN ones.
71     
72     final String[][] nonEnPairs = new String[][] {
73         {"AR", "DE" },
74         {"AR", "ES" },
75         {"AR", "FR" },
76         {"AR", "IT" },
77         {"AR", "JA" },
78         {"AR", "RU" },
79         {"AR", "ZH" },
80         
81         {"DE", "FR" },
82         {"DE", "CA" },  // Catalan
83         {"DE", "CS" },  // Czech
84         {"DE", "EO" },  // Esperanto
85         {"DE", "ES" },
86         {"DE", "FR" },
87         {"DE", "HU" },  // Hungarian
88         {"DE", "IT" },
89         {"DE", "JA" },
90         {"DE", "LA" },  // Latin
91         {"DE", "PL" },  // Polish
92         {"DE", "RU" },
93         {"DE", "SV" },  // Swedish
94         {"DE", "ZH" },
95
96         
97         {"FR", "BG" },  // Bulgarian
98         {"FR", "CS" },  // Czech
99         {"FR", "DE" },
100         {"FR", "ES" },
101         {"FR", "IT" },
102         {"FR", "JA" },
103         {"FR", "LA" },
104         {"FR", "NL" },  // Dutch
105         {"FR", "RU" },
106         {"FR", "ZH" },
107
108         {"IT", "DE" },
109         {"IT", "EL" },  // Greek
110         {"IT", "ES" },
111         {"IT", "FR" },
112         {"IT", "HU" },
113         {"IT", "JA" },
114         {"IT", "LA" },  // Latin
115         {"IT", "LV" },  // Latvian
116         {"IT", "NL" },
117         {"IT", "PL" },
118         {"IT", "RU" },
119         {"IT", "SV" },
120         {"IT", "ZH" },
121
122         {"JA", "ZH" },
123         {"JA", "AR" },
124
125         {"ZH", "AR" },
126         {"ZH", "DE" },
127         {"ZH", "ES" },
128         {"ZH", "FR" },
129         {"ZH", "IT" },
130
131         
132         {"NO", "SV" },
133         {"NO", "FI" },
134         {"FI", "SV" },
135         {"AR", "HE" },
136         {"KO", "JA" },
137         {"KO", "ZH" },
138     };
139     
140     final Set<List<String>> done = new LinkedHashSet<List<String>>();
141     for (final String[] pair : nonEnPairs) {
142       Arrays.sort(pair);
143       final List<String> pairList = Arrays.asList(pair);
144       if (done.contains(pairList)) {
145         continue;
146       }
147       done.add(pairList);
148       
149       final String lang1 = pair[0];
150       final String lang2 = pair[1];
151       
152       final String dictFile = String.format("%s/%s-%s_enwiktionary_BETA.quickdic", 
153           OUTPUTS, lang1, lang2);
154       System.out.println("building dictFile: " + dictFile);
155
156       if (!isoToStoplist.containsKey(lang1)) {
157         isoToStoplist.put(lang1, "empty.txt");
158       }
159       if (!isoToStoplist.containsKey(lang2)) {
160         isoToStoplist.put(lang2, "empty.txt");
161       }
162       
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),
170
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),
176       });
177     }
178     if (1==1) {
179       return;
180     }
181
182
183     // Now build the EN ones.
184     
185 //    isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
186     //isoToWikiName.clear();
187     boolean go = true;
188     for (final String foreignIso : isoToWikiName.keySet()) {
189       if (foreignIso.equals("GD")) {
190         go = true;
191       }
192       if (!go) {
193         continue;
194       }
195
196         final String dictFile = String.format("%s/EN-%s_enwiktionary.quickdic", OUTPUTS, foreignIso);
197         System.out.println("building dictFile: " + dictFile);
198         
199         if (!isoToStoplist.containsKey(foreignIso)) {
200           isoToStoplist.put(foreignIso, "empty.txt");
201         }
202         if (!isoToDedication.containsKey(foreignIso)) {
203           isoToDedication.put(foreignIso, "");
204         }
205         if (!isoToRegex.containsKey(foreignIso)) {
206           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
207         }
208   
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)),
216
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(),
223             "--input2EnIndex=1",
224
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(),
231             "--input3EnIndex=1",
232
233         });
234         
235     }  // foreignIso
236
237     // Now special case German-English.
238
239     final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.quickdic", OUTPUTS);
240     DictionaryBuilder.main(new String[] {
241         "--dictOut=" + dictFile,
242         "--lang1=DE",
243         "--lang2=EN",
244         String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
245         String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
246         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
247
248         "--input4=" + INPUTS + "de-en_chemnitz.txt",
249         "--input4Name=chemnitz",
250         "--input4Charset=UTF8",
251         "--input4Format=chemnitz",
252         
253         "--input2=" + INPUTS + "wikiSplit/en/DE.data",
254         "--input2Name=enwiktionary.DE",
255         "--input2Format=enwiktionary",
256         "--input2WiktionaryType=EnForeign",
257         "--input2LangPattern=German",
258         "--input2LangCodePattern=de",
259         "--input2EnIndex=2",
260
261         "--input3=" + INPUTS + "wikiSplit/en/EN.data",
262         "--input3Name=enwiktionary.english",
263         "--input3Format=enwiktionary",
264         "--input3WiktionaryType=EnToTranslation",
265         "--input3LangPattern=German",
266         "--input3LangCodePattern=de",
267         "--input3EnIndex=2",
268     });
269     
270   }
271     
272 }