1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 package com.hughes.android.dictionary.engine;
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;
24 import junit.framework.TestCase;
26 public class DictionaryBuilderMain extends TestCase {
29 final String nameRegex;
31 public Lang(String nameRegex, String code) {
32 this.nameRegex = nameRegex;
38 public static void main(final String[] args) throws Exception {
40 Lang[] langs1 = new Lang[] {
41 new Lang("^English$", "EN"),
42 //new Lang("^German$", "DE"),
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"),
91 for (final Lang lang1 : langs1) {
92 for (final Lang lang2 : langs2) {
93 if (lang1.nameRegex.equals(lang2.nameRegex)) {
98 if (lang2.code.equals("EN")) {
101 if (lang1.code.equals("EN")) {
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),
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),
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));
136 DictionaryBuilder.main(new String[] {
137 "--dictOut=dictOutputs/DE-EN_chemnitz.quickdic",
140 "--dictInfo=@dictInputs/de-en_chemnitz.info",
142 "--input1=dictInputs/de-en_chemnitz.txt",
143 "--input1Name=chemnitz",
144 "--input1Charset=UTF8",
145 "--input1Format=chemnitz",
148 DictionaryBuilder.main(new String[] {
149 "--dictOut=dictOutputs/de-en_all.quickdic",
152 "--dictInfo=@dictInputs/de-en_all.info",
154 "--input2=dictInputs/de-en_chemnitz.txt",
155 "--input2Name=dictcc",
156 "--input2Charset=UTF8",
157 "--input2Format=chemnitz",
159 "--input3=dictInputs/de-en_dictcc.txt",
160 "--input3Name=dictcc",
161 "--input3Charset=UTF8",
162 "--input3Format=dictcc",
164 "--input1=dictInputs/enwiktionary-20101015-pages-articles",
165 "--input1Name=enwiktionary",
166 "--input1Format=enwiktionary",
167 "--input1TranslationPattern1=^German$",
168 "--input1TranslationPattern2=^English$",