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", "es.txt"),
55 // new Lang("^.*Greek.*$", "EL", "greek.data", "el.txt"),
56 // new Lang("^.*Japanese.*$", "JA", "japanese.data", "empty.txt"),
57 // new Lang("^.*Chinese.*$|^.*Mandarin.*$", "ZH", "mandarin.data", "empty.txt"),
58 new Lang("^.*Afrikaans.*$", "AF", "afrikaans.data", "empty.txt"),
59 new Lang("^.*Arabic.*$", "AR", "".data, "empty.txt"),
60 new Lang("^.*Hebrew.*$", "HE"),
61 new Lang("^.*Hindi.*$", "HI"),
62 new Lang("^.*Icelandic.*$", "IS"),
63 new Lang("^.*Irish.*$", "GA"),
64 new Lang("^.*Korean.*$", "KO"),
65 new Lang("^.*Maori.*$", "MI"),
66 new Lang("^.*Norwegian.*$", "NO"),
67 new Lang("^.*Persian.*$", "FA"),
68 new Lang("^.*Portuguese.*$", "PT"),
69 new Lang("^.*Romanian.*$", "RO"),
70 new Lang("^.*Russian.*$", "RU"),
71 new Lang("^.*Sanskrit.*$", "SA"),
72 new Lang("^.*Serbian.*$", "SR"),
73 new Lang("^.*Swedish.*$", "SV"),
74 new Lang("^.*Tajik.*$", "TG"),
75 new Lang("^.*Thai.*$", "TH"),
76 new Lang("^.*Tibetan.*$", "BO"),
77 new Lang("^.*Turkish.*$", "TR"),
78 new Lang("^.*Ukranian.*$", "UK"),
79 new Lang("^.*Vietnamese.*$", "VI"),
80 new Lang("^.*Welsh.*$", "CY"),
81 new Lang("^.*Zulu.*$", "ZU"),
82 new Lang("^.*Croation.*$", "HR"),
83 new Lang("^.*Czech.*$", "CS"),
84 new Lang("^.*Dutch.*$", "NL"),
85 new Lang("^.*Finnish.*$", "FI"),
87 new Lang("^German$", "DE"),
88 new Lang("^Armenian$", "HY"),
89 new Lang("^English$", "EN"),
90 new Lang("^Kurdish$", "KU"),
91 new Lang("^Lithuanian$", "LT"),
92 new Lang("^Malay$", "MS"),
93 new Lang("^Mongolian$", "MN"),
94 new Lang("^Somali$", "SO"),
95 new Lang("^Sudanese$", "SU"),
96 new Lang("^Yiddish$", "YI"),
100 for (final Lang lang1 : langs1) {
101 for (final Lang lang2 : langs2) {
102 if (lang1.nameRegex.equals(lang2.nameRegex)) {
107 Lang nonEnglish = null;
108 if (lang2.isoCode.equals("EN")) {
112 if (lang1.isoCode.equals("EN")) {
116 assert nonEnglish != null;
118 final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode);
119 System.out.println("building dictFile: " + dictFile);
120 DictionaryBuilder.main(new String[] {
121 String.format("--dictOut=%s", dictFile),
122 String.format("--lang1=%s", lang1.isoCode),
123 String.format("--lang2=%s", lang2.isoCode),
124 String.format("--lang1Stoplist=%s", STOPLISTS + lang1.stoplistFile),
125 String.format("--lang2Stoplist=%s", STOPLISTS + lang2.stoplistFile),
126 String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode),
128 "--input2=" + INPUTS + "enWikiSplit/" + nonEnglish.wikiSplit,
129 "--input2Name=enwiktionary." + nonEnglish.wikiSplit,
130 "--input2Format=enwiktionary",
131 "--input2LangPattern=" + nonEnglish.nameRegex,
132 "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(),
133 "--input2EnIndex=" + enIndex,
135 "--input3=" + INPUTS + "enWikiSplit/english.data",
136 "--input3Name=enwiktionary.english",
137 "--input3Format=enwiktionary",
138 "--input3LangPattern=" + nonEnglish.nameRegex,
139 "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(),
140 "--input3EnIndex=" + enIndex,
144 // Print the entries for diffing.
145 final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
146 final Dictionary dict = new Dictionary(raf);
147 final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
148 final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
149 Collections.sort(sorted);
150 for (final PairEntry pairEntry : sorted) {
151 textOut.println(pairEntry.getRawText(false));
159 DictionaryBuilder.main(new String[] {
160 "--dictOut=" + OUTPUTS + "DE-EN_all_free.quickdic",
163 "--dictInfo=@" + INPUTS + "de-en_all_free.info",
165 "--input1=" + INPUTS + "de-en_chemnitz.txt",
166 "--input1Name=chemnitz",
167 "--input1Charset=UTF8",
168 "--input1Format=chemnitz",
171 DictionaryBuilder.main(new String[] {
172 "--dictOut=" + OUTPUTS + "de-en_all.quickdic",
175 "--dictInfo=@" + INPUTS + "de-en_all.info",
177 "--input2=" + INPUTS + "de-en_chemnitz.txt",
178 "--input2Name=dictcc",
179 "--input2Charset=UTF8",
180 "--input2Format=chemnitz",
182 "--input3=" + INPUTS + "/NONFREE/de-en_dictcc.txt",
183 "--input3Name=dictcc",
184 "--input3Charset=UTF8",
185 "--input3Format=dictcc",