]> 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     DictionaryBuilder.main(new String[] {
26         "--dictOut=dictOutputs/DE-EN_chemnitz.quickdic",
27         "--lang1=DE",
28         "--lang2=EN",
29         "--dictInfo=@dictInputs/de-en_chemnitz.info",
30
31         "--input1=dictInputs/de-en_chemnitz.txt",
32         "--input1Name=chemnitz",
33         "--input1Charset=UTF8",
34         "--input1Format=chemnitz",
35     });
36
37
38     Lang[] langs1 = new Lang[] { 
39         new Lang("^English$", "EN"),
40         new Lang("^German$", "DE"),
41     };
42     Lang[] langs2 = new Lang[] { 
43         new Lang("^Italian$", "IT"),
44         new Lang("^German$", "DE"),
45         new Lang("^Afrikaans$", "AF"),
46         new Lang("^Armenian$", "HY"),
47         new Lang("^Arabic$", "AR"),
48         new Lang("^Chinese$|^Mandarin$", "ZH"),
49         new Lang("^Croation$", "HR"),
50         new Lang("^Czech$", "CS"),
51         new Lang("^Dutch$", "NL"),
52         new Lang("^English$", "EN"),
53         new Lang("^Finnish$", "FI"),
54         new Lang("^French$", "FR"),
55         new Lang("^Greek$", "EL"),
56         new Lang("^Hebrew$", "HE"),
57         new Lang("^Hindi$", "HI"),
58         new Lang("^Icelandic$", "IS"),
59         new Lang("^Irish$", "GA"),
60         new Lang("^Japanese$", "JA"),
61         new Lang("^Korean$", "KO"),
62         new Lang("^Kurdish$", "KU"),
63         new Lang("^Lithuanian$", "LT"),
64         new Lang("^Malay$", "MS"),
65         new Lang("^Maori$", "MI"),
66         new Lang("^Mongolian$", "MN"),
67         new Lang("^Norwegian$", "NO"),
68         new Lang("^Persian$", "FA"),
69         new Lang("^Portuguese$", "PT"),
70         new Lang("^Romanian$", "RO"),
71         new Lang("^Russian$", "RU"),
72         new Lang("^Sanskrit$", "SA"),
73         new Lang("^Serbian$", "SR"),
74         new Lang("^Somali$", "SO"),
75         new Lang("^Spanish$", "ES"),
76         new Lang("^Sudanese$", "SU"),
77         new Lang("^Swedish$", "SV"),
78         new Lang("^Tajik$", "TG"),
79         new Lang("^Thai$", "TH"),
80         new Lang("^Tibetan$", "BO"),
81         new Lang("^Turkish$", "TR"),
82         new Lang("^Ukranian$", "UK"),
83         new Lang("^Vietnamese$", "VI"),
84         new Lang("^Welsh$", "CY"),
85         new Lang("^Yiddish$", "YI"),
86         new Lang("^Zulu$", "ZU"),
87     };
88     
89     for (final Lang lang1 : langs1) {
90       for (final Lang lang2 : langs2) {
91         if (lang1.nameRegex.equals(lang2.nameRegex)) {
92           continue;
93         }
94         
95         int enIndex = -1;
96         if (lang2.code.equals("EN")) {
97           enIndex = 2;
98         }
99         if (lang1.code.equals("EN")) {
100           enIndex = 1;
101         }
102
103         final String dictFile = String.format("dictOutputs/%s-%s_enwiktionary.quickdic", lang1.code, lang2.code);
104         System.out.println("building dictFile: " + dictFile);
105         DictionaryBuilder.main(new String[] {
106             String.format("--dictOut=%s", dictFile),
107             String.format("--lang1=%s", lang1.code),
108             String.format("--lang2=%s", lang2.code),
109             String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.code, lang2.code),
110
111             "--input1=dictInputs/enwiktionary-20110205-pages-articles.xml",
112             "--input1Name=enwiktionary",
113             "--input1Format=enwiktionary",
114             String.format("--input1TranslationPattern1=%s", lang1.nameRegex),
115             String.format("--input1TranslationPattern2=%s", lang2.nameRegex),
116             String.format("--input1EnIndex=%d", enIndex),
117         });
118         
119         // Print the entries for diffing.
120         final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
121         final Dictionary dict = new Dictionary(raf);
122         final PrintWriter textOut = new PrintWriter(new File(dictFile + ".txt"));
123         final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
124         Collections.sort(sorted);
125         for (final PairEntry pairEntry : sorted) {
126           textOut.println(pairEntry.getRawText(false));
127         }
128         textOut.close();
129         raf.close();
130
131       }  // langs2
132     }  // langs1
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 }