1 package com.hughes.android.dictionary.engine;
4 import java.io.PrintWriter;
5 import java.io.RandomAccessFile;
6 import java.util.ArrayList;
7 import java.util.Collections;
10 import junit.framework.TestCase;
12 public class DictionaryBuilderMain extends TestCase {
15 final String nameRegex;
17 public Lang(String nameRegex, String code) {
18 this.nameRegex = nameRegex;
24 public static void main(final String[] args) throws Exception {
26 Lang[] langs1 = new Lang[] {
27 new Lang("^English$", "EN"),
28 new Lang("^German$", "DE"),
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"),
77 for (final Lang lang1 : langs1) {
78 for (final Lang lang2 : langs2) {
79 if (lang1.nameRegex.equals(lang2.nameRegex)) {
84 if (lang2.code.equals("EN")) {
87 if (lang1.code.equals("EN")) {
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),
99 "--input1=dictInputs/enwiktionary-20101015-pages-articles",
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),
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));
122 DictionaryBuilder.main(new String[] {
123 "--dictOut=dictOutputs/de-en_all.quickdic",
126 "--dictInfo=@dictInputs/de-en_all.info",
128 "--input2=dictInputs/de-en_chemnitz.txt",
129 "--input2Name=dictcc",
130 "--input2Charset=UTF8",
131 "--input2Format=chemnitz",
133 "--input3=dictInputs/de-en_dictcc.txt",
134 "--input3Name=dictcc",
135 "--input3Charset=UTF8",
136 "--input3Format=dictcc",
138 "--input1=dictInputs/enwiktionary-20101015-pages-articles",
139 "--input1Name=enwiktionary",
140 "--input1Format=enwiktionary",
141 "--input1TranslationPattern1=^German$",
142 "--input1TranslationPattern2=^English$",
147 DictionaryBuilder.main(new String[] {
148 "--dictOut=dictOutputs/de-en_chemnitz.quickdic",
151 "--dictInfo=@dictInputs/de-en_chemnitz.info",
153 "--input1=dictInputs/de-en_chemnitz.txt",
154 "--input1Name=dictcc",
155 "--input1Charset=UTF8",
156 "--input1Format=chemnitz",