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 {
28 static final String INPUTS = "../DictionaryData/inputs/";
29 static final String STOPLISTS = "../DictionaryData/inputs/stoplists/";
30 static final String OUTPUTS = "../DictionaryData/outputs/";
33 final String nameRegex;
35 final String wikiSplit;
36 final String stoplistFile;
37 public Lang(String nameRegex, String code, final String wikiSplit, final String stoplistFile) {
38 this.nameRegex = nameRegex;
40 this.wikiSplit = wikiSplit;
41 this.stoplistFile = stoplistFile;
46 public static void main(final String[] args) throws Exception {
48 Lang[] langs1 = new Lang[] {
49 new Lang("^English$", "EN", null, "en.txt"),
51 Lang[] langs2 = new Lang[] {
52 new Lang("^.*Italian.*$", "IT", "italian.data", "it.txt"),
53 new Lang("^.*French.*$", "FR", "french.data", "empty.txt"),
54 new Lang("^.*Spanish.*$", "ES", "spanish.data", "empty.txt"),
55 new Lang("^.*Greek.*$", "EL", "greek.data", "empty.txt"),
56 new Lang("^.*Japanese.*$", "JA", "japanese.data", "empty.txt"),
57 new Lang("^.*Chinese.*$|^.*Mandarin.*$", "ZH", "mandarin.data", "empty.txt"),
59 new Lang("^German$", "DE"),
60 new Lang("^Afrikaans$", "AF"),
61 new Lang("^Armenian$", "HY"),
62 new Lang("^Arabic$", "AR"),
63 new Lang("^Croation$", "HR"),
64 new Lang("^Czech$", "CS"),
65 new Lang("^Dutch$", "NL"),
66 new Lang("^English$", "EN"),
67 new Lang("^Finnish$", "FI"),
68 new Lang("^Hebrew$", "HE"),
69 new Lang("^Hindi$", "HI"),
70 new Lang("^Icelandic$", "IS"),
71 new Lang("^Irish$", "GA"),
72 new Lang("^Korean$", "KO"),
73 new Lang("^Kurdish$", "KU"),
74 new Lang("^Lithuanian$", "LT"),
75 new Lang("^Malay$", "MS"),
76 new Lang("^Maori$", "MI"),
77 new Lang("^Mongolian$", "MN"),
78 new Lang("^Norwegian$", "NO"),
79 new Lang("^Persian$", "FA"),
80 new Lang("^Portuguese$", "PT"),
81 new Lang("^Romanian$", "RO"),
82 new Lang("^Russian$", "RU"),
83 new Lang("^Sanskrit$", "SA"),
84 new Lang("^Serbian$", "SR"),
85 new Lang("^Somali$", "SO"),
86 new Lang("^Sudanese$", "SU"),
87 new Lang("^Swedish$", "SV"),
88 new Lang("^Tajik$", "TG"),
89 new Lang("^Thai$", "TH"),
90 new Lang("^Tibetan$", "BO"),
91 new Lang("^Turkish$", "TR"),
92 new Lang("^Ukranian$", "UK"),
93 new Lang("^Vietnamese$", "VI"),
94 new Lang("^Welsh$", "CY"),
95 new Lang("^Yiddish$", "YI"),
96 new Lang("^Zulu$", "ZU"),*/
99 for (final Lang lang1 : langs1) {
100 for (final Lang lang2 : langs2) {
101 if (lang1.nameRegex.equals(lang2.nameRegex)) {
106 Lang nonEnglish = null;
107 if (lang2.isoCode.equals("EN")) {
111 if (lang1.isoCode.equals("EN")) {
115 assert nonEnglish != null;
117 final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode);
118 System.out.println("building dictFile: " + dictFile);
119 DictionaryBuilder.main(new String[] {
120 String.format("--dictOut=%s", dictFile),
121 String.format("--lang1=%s", lang1.isoCode),
122 String.format("--lang2=%s", lang2.isoCode),
123 String.format("--lang1Stoplist=%s", STOPLISTS + lang1.stoplistFile),
124 String.format("--lang2Stoplist=%s", STOPLISTS + lang2.stoplistFile),
125 String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode),
127 "--input2=" + INPUTS + "enWikiSplit/" + nonEnglish.wikiSplit,
128 "--input2Name=enwiktionary." + nonEnglish.wikiSplit,
129 "--input2Format=enwiktionary",
130 "--input2LangPattern=" + nonEnglish.nameRegex,
131 "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(),
132 "--input2EnIndex=" + enIndex,
134 "--input3=" + INPUTS + "enWikiSplit/english.data",
135 "--input3Name=enwiktionary.english",
136 "--input3Format=enwiktionary",
137 "--input3LangPattern=" + nonEnglish.nameRegex,
138 "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(),
139 "--input3EnIndex=" + enIndex,
143 // Print the entries for diffing.
144 final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
145 final Dictionary dict = new Dictionary(raf);
146 final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
147 final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
148 Collections.sort(sorted);
149 for (final PairEntry pairEntry : sorted) {
150 textOut.println(pairEntry.getRawText(false));
158 DictionaryBuilder.main(new String[] {
159 "--dictOut=" + OUTPUTS + "DE-EN_chemnitz.quickdic",
162 "--dictInfo=@" + INPUTS + "de-en_chemnitz.info",
164 "--input1=" + INPUTS + "de-en_chemnitz.txt",
165 "--input1Name=chemnitz",
166 "--input1Charset=UTF8",
167 "--input1Format=chemnitz",
170 DictionaryBuilder.main(new String[] {
171 "--dictOut=" + OUTPUTS + "de-en_all.quickdic",
174 "--dictInfo=@" + INPUTS + "de-en_all.info",
176 "--input2=" + INPUTS + "de-en_chemnitz.txt",
177 "--input2Name=dictcc",
178 "--input2Charset=UTF8",
179 "--input2Format=chemnitz",
181 "--input3=" + INPUTS + "/NONFREE/de-en_dictcc.txt",
182 "--input3Name=dictcc",
183 "--input3Charset=UTF8",
184 "--input3Format=dictcc",