]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
2 types of TokenRow.
[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   static final String VERSION_SUFFIX = "v002";
31
32   
33   public static void main(final String[] args) throws Exception {
34     
35     // Builds all the dictionaries it can, outputs list to a text file.
36     
37     final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(EnWiktionaryLangs.isoCodeToWikiName);
38     isoToWikiName.remove("EN");
39     isoToWikiName.remove("DE");
40
41     final Map<String,String>  isoToDedication = new LinkedHashMap<String, String>();
42     isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
43     isoToDedication.put("HR", "Croatian dictionary dedicated to Ines Viskic and Miro Kresonja.");
44     isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
45     // German handled in file.
46     isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
47     isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe!  Ti amo!");
48     isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
49     isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
50     isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
51     isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
52     isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
53     isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
54     isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
55
56     final Map<String,String>  isoToStoplist = new LinkedHashMap<String, String>();
57     isoToStoplist.put("DE", "de.txt");
58     isoToStoplist.put("EN", "en.txt");
59     isoToStoplist.put("ES", "es.txt");
60     isoToStoplist.put("IT", "it.txt");
61     isoToStoplist.put("FR", "fr.txt");
62
63     final Map<String,String>  isoToRegex = new LinkedHashMap<String, String>();
64     // HACK: The missing "e" prevents a full match, causing "Cantonese" to be appended to the entries.
65     isoToRegex.put("ZH", "Chinese|Mandarin|Cantones");
66     
67 //    isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
68     //isoToWikiName.clear();
69     boolean go = true;
70     for (final String foreignIso : isoToWikiName.keySet()) {
71       if (foreignIso.equals("SK")) {
72         go = true;
73       }
74       if (!go) {
75         continue;
76       }
77
78         final String dictFile = String.format("%s/EN-%s_enwiktionary.%s.quickdic", OUTPUTS, foreignIso, VERSION_SUFFIX);
79         System.out.println("building dictFile: " + dictFile);
80         
81         if (!isoToStoplist.containsKey(foreignIso)) {
82           isoToStoplist.put(foreignIso, "empty.txt");
83         }
84         if (!isoToDedication.containsKey(foreignIso)) {
85           isoToDedication.put(foreignIso, "");
86         }
87         if (!isoToRegex.containsKey(foreignIso)) {
88           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
89         }
90   
91         DictionaryBuilder.main(new String[] {
92             String.format("--dictOut=%s", dictFile),
93             String.format("--lang1=EN"),
94             String.format("--lang2=%s", foreignIso),
95             String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
96             String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
97             String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary.  %s", foreignIso, isoToDedication.get(foreignIso)),
98
99             "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
100             "--input2Name=enwiktionary." + foreignIso,
101             "--input2Format=enwiktionary",
102             "--input2LangPattern=" + isoToRegex.get(foreignIso),
103             "--input2LangCodePattern=" + foreignIso.toLowerCase(),
104             "--input2EnIndex=1",
105
106             "--input3=" + INPUTS + "enWikiSplit/EN.data",
107             "--input3Name=enwiktionary.english",
108             "--input3Format=enwiktionary",
109             "--input3LangPattern=" + isoToRegex.get(foreignIso),
110             "--input3LangCodePattern=" + foreignIso.toLowerCase(),
111             "--input3EnIndex=1",
112
113         });
114         
115     }  // foreignIso
116
117     final String dictFile = String.format("%s/DE-EN_chemnitz_enwiktionary.%s.quickdic", OUTPUTS, VERSION_SUFFIX);
118     DictionaryBuilder.main(new String[] {
119         "--dictOut=" + dictFile,
120         "--lang1=DE",
121         "--lang2=EN",
122         String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
123         String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
124         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
125
126         "--input4=" + INPUTS + "de-en_chemnitz.txt",
127         "--input4Name=chemnitz",
128         "--input4Charset=UTF8",
129         "--input4Format=chemnitz",
130         
131         "--input2=" + INPUTS + "enWikiSplit/DE.data",
132         "--input2Name=enwiktionary.DE",
133         "--input2Format=enwiktionary",
134         "--input2LangPattern=German",
135         "--input2LangCodePattern=de",
136         "--input2EnIndex=2",
137
138         "--input3=" + INPUTS + "enWikiSplit/EN.data",
139         "--input3Name=enwiktionary.english",
140         "--input3Format=enwiktionary",
141         "--input3LangPattern=German",
142         "--input3LangCodePattern=de",
143         "--input3EnIndex=2",
144     });
145     
146   }
147     
148 }