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