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