]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
Fixing.
[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.io.File;
18 import java.io.PrintWriter;
19 import java.io.RandomAccessFile;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23
24 import junit.framework.TestCase;
25
26 public class DictionaryBuilderMain extends TestCase {
27   
28   static final String INPUTS = "../DictionaryData/inputs/";
29   static final String OUTPUTS = "../DictionaryData/outputs/";
30   
31   static class Lang {
32     final String nameRegex;
33     final String isoCode;
34     final String wikiSplit;
35     public Lang(String nameRegex, String code, final String wikiSplit) {
36       this.nameRegex = nameRegex;
37       this.isoCode = code;
38       this.wikiSplit = wikiSplit;
39     }
40   }
41   
42   
43   public static void main(final String[] args) throws Exception {
44
45     Lang[] langs1 = new Lang[] { 
46         new Lang("^English$", "EN", null),
47     };
48     Lang[] langs2 = new Lang[] { 
49         new Lang("^.*Italian.*$", "IT", "italian.data"),
50         new Lang("^.*Greek.*$", "EL", "greek.data"),
51         new Lang("^.*Spanish.*$", "ES", "spanish.data"),
52         /*
53         new Lang("^German$", "DE"),
54         new Lang("^Afrikaans$", "AF"),
55         new Lang("^Armenian$", "HY"),
56         new Lang("^Arabic$", "AR"),
57         new Lang("^Chinese$|^Mandarin$", "ZH"),
58         new Lang("^Croation$", "HR"),
59         new Lang("^Czech$", "CS"),
60         new Lang("^Dutch$", "NL"),
61         new Lang("^English$", "EN"),
62         new Lang("^Finnish$", "FI"),
63         new Lang("^French$", "FR"),
64         new Lang("^Hebrew$", "HE"),
65         new Lang("^Hindi$", "HI"),
66         new Lang("^Icelandic$", "IS"),
67         new Lang("^Irish$", "GA"),
68         new Lang("^Japanese$", "JA"),
69         new Lang("^Korean$", "KO"),
70         new Lang("^Kurdish$", "KU"),
71         new Lang("^Lithuanian$", "LT"),
72         new Lang("^Malay$", "MS"),
73         new Lang("^Maori$", "MI"),
74         new Lang("^Mongolian$", "MN"),
75         new Lang("^Norwegian$", "NO"),
76         new Lang("^Persian$", "FA"),
77         new Lang("^Portuguese$", "PT"),
78         new Lang("^Romanian$", "RO"),
79         new Lang("^Russian$", "RU"),
80         new Lang("^Sanskrit$", "SA"),
81         new Lang("^Serbian$", "SR"),
82         new Lang("^Somali$", "SO"),
83         new Lang("^Sudanese$", "SU"),
84         new Lang("^Swedish$", "SV"),
85         new Lang("^Tajik$", "TG"),
86         new Lang("^Thai$", "TH"),
87         new Lang("^Tibetan$", "BO"),
88         new Lang("^Turkish$", "TR"),
89         new Lang("^Ukranian$", "UK"),
90         new Lang("^Vietnamese$", "VI"),
91         new Lang("^Welsh$", "CY"),
92         new Lang("^Yiddish$", "YI"),
93         new Lang("^Zulu$", "ZU"),*/
94     };
95     
96     for (final Lang lang1 : langs1) {
97       for (final Lang lang2 : langs2) {
98         if (lang1.nameRegex.equals(lang2.nameRegex)) {
99           continue;
100         }
101         
102         int enIndex = -1;
103         Lang nonEnglish = null;
104         if (lang2.isoCode.equals("EN")) {
105           enIndex = 2;
106           nonEnglish = lang1;
107         }
108         if (lang1.isoCode.equals("EN")) {
109           enIndex = 1;
110           nonEnglish = lang2;
111         }
112         assert nonEnglish != null;
113
114         final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode);
115         System.out.println("building dictFile: " + dictFile);
116         DictionaryBuilder.main(new String[] {
117             String.format("--dictOut=%s", dictFile),
118             String.format("--lang1=%s", lang1.isoCode),
119             String.format("--lang2=%s", lang2.isoCode),
120             String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode),
121
122             "--input2=" + INPUTS + "wikiSplit/" + nonEnglish.wikiSplit,
123             "--input2Name=enwiktionary." + nonEnglish.wikiSplit,
124             "--input2Format=enwiktionary",
125             "--input2LangPattern=" + nonEnglish.nameRegex,
126             "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(),
127             "--input2EnIndex=" + enIndex,
128
129             "--input3=" + INPUTS + "wikiSplit/english.data",
130             "--input3Name=enwiktionary.english",
131             "--input3Format=enwiktionary",
132             "--input3LangPattern=" + nonEnglish.nameRegex,
133             "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(),
134             "--input3EnIndex=" + enIndex,
135
136         });
137         
138         // Print the entries for diffing.
139         final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
140         final Dictionary dict = new Dictionary(raf);
141         final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
142         final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
143         Collections.sort(sorted);
144         for (final PairEntry pairEntry : sorted) {
145           textOut.println(pairEntry.getRawText(false));
146         }
147         textOut.close();
148         raf.close();
149
150       }  // langs2
151     }  // langs1
152
153     DictionaryBuilder.main(new String[] {
154         "--dictOut=" + OUTPUTS + "DE-EN_chemnitz.quickdic",
155         "--lang1=DE",
156         "--lang2=EN",
157         "--dictInfo=@" + INPUTS + "de-en_chemnitz.info",
158
159         "--input1=" + INPUTS + "de-en_chemnitz.txt",
160         "--input1Name=chemnitz",
161         "--input1Charset=UTF8",
162         "--input1Format=chemnitz",
163     });
164
165     DictionaryBuilder.main(new String[] {
166         "--dictOut=" + OUTPUTS + "de-en_all.quickdic",
167         "--lang1=DE",
168         "--lang2=EN",
169         "--dictInfo=@" + INPUTS + "de-en_all.info",
170
171         "--input2=" + INPUTS + "de-en_chemnitz.txt",
172         "--input2Name=dictcc",
173         "--input2Charset=UTF8",
174         "--input2Format=chemnitz",
175
176         "--input3=" + INPUTS + "/copyrighted/de-en_dictcc.txt",
177         "--input3Name=dictcc",
178         "--input3Charset=UTF8",
179         "--input3Format=dictcc",
180         
181         // TODO: wiktionary
182     });
183
184   }
185   
186 }