]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
zipSize, overrideStoplist-> special isMainEntry, tagalog, trying to
[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.LinkedHashMap;
18 import java.util.Map;
19
20 import junit.framework.TestCase;
21
22 import com.hughes.android.dictionary.parser.enwiktionary.EnWiktionaryLangs;
23
24 public class DictionaryBuilderMain extends TestCase {
25   
26   static final String INPUTS = "data/inputs/";
27   static final String STOPLISTS = "data/inputs/stoplists/";
28   static final String OUTPUTS = "data/outputs/";  
29     
30   public static void main(final String[] args) throws Exception {
31     
32     // Builds all the dictionaries it can, outputs list to a text file.
33     
34     final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(EnWiktionaryLangs.isoCodeToWikiName);
35     isoToWikiName.remove("EN");
36     isoToWikiName.remove("DE");
37
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!");
52
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");
59
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");
63     
64 //    isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
65     //isoToWikiName.clear();
66     boolean go = true;
67     for (final String foreignIso : isoToWikiName.keySet()) {
68       if (foreignIso.equals("blah")) {
69         go = true;
70       }
71       if (!go) {
72         continue;
73       }
74
75         final String dictFile = String.format("%s/EN-%s_enwiktionary.quickdic", OUTPUTS, foreignIso);
76         System.out.println("building dictFile: " + dictFile);
77         
78         if (!isoToStoplist.containsKey(foreignIso)) {
79           isoToStoplist.put(foreignIso, "empty.txt");
80         }
81         if (!isoToDedication.containsKey(foreignIso)) {
82           isoToDedication.put(foreignIso, "");
83         }
84         if (!isoToRegex.containsKey(foreignIso)) {
85           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
86         }
87   
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.\n\n%s", foreignIso, isoToDedication.get(foreignIso)),
95
96             "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
97             "--input2Name=enwiktionary." + foreignIso,
98             "--input2Format=enwiktionary",
99             "--input2LangPattern=" + isoToRegex.get(foreignIso),
100             "--input2LangCodePattern=" + foreignIso.toLowerCase(),
101             "--input2EnIndex=1",
102
103             "--input3=" + INPUTS + "enWikiSplit/EN.data",
104             "--input3Name=enwiktionary.english",
105             "--input3Format=enwiktionary",
106             "--input3LangPattern=" + isoToRegex.get(foreignIso),
107             "--input3LangCodePattern=" + foreignIso.toLowerCase(),
108             "--input3EnIndex=1",
109
110         });
111         
112     }  // foreignIso
113
114     final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.quickdic", OUTPUTS);
115     DictionaryBuilder.main(new String[] {
116         "--dictOut=" + dictFile,
117         "--lang1=DE",
118         "--lang2=EN",
119         String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
120         String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
121         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
122
123         "--input4=" + INPUTS + "de-en_chemnitz.txt",
124         "--input4Name=chemnitz",
125         "--input4Charset=UTF8",
126         "--input4Format=chemnitz",
127         
128         "--input2=" + INPUTS + "enWikiSplit/DE.data",
129         "--input2Name=enwiktionary.DE",
130         "--input2Format=enwiktionary",
131         "--input2LangPattern=German",
132         "--input2LangCodePattern=de",
133         "--input2EnIndex=2",
134
135         "--input3=" + INPUTS + "enWikiSplit/EN.data",
136         "--input3Name=enwiktionary.english",
137         "--input3Format=enwiktionary",
138         "--input3LangPattern=German",
139         "--input3LangCodePattern=de",
140         "--input3EnIndex=2",
141     });
142     
143   }
144     
145 }