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