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 OUTPUTS = "../DictionaryData/outputs/";
32 final String nameRegex;
34 final String wikiSplit;
35 public Lang(String nameRegex, String code, final String wikiSplit) {
36 this.nameRegex = nameRegex;
38 this.wikiSplit = wikiSplit;
43 public static void main(final String[] args) throws Exception {
45 Lang[] langs1 = new Lang[] {
46 new Lang("^English$", "EN", null),
48 Lang[] langs2 = new Lang[] {
49 new Lang("^.*Italian.*$", "IT", "italian.data"),
50 new Lang("^.*Greek.*$", "EL", "greek.data"),
51 new Lang("^.*Spanish.*$", "ES", "spanish.data"),
53 new Lang("^German$", "DE"),
54 new Lang("^Afrikaans$", "AF"),
55 new Lang("^Armenian$", "HY"),
56 new Lang("^Arabic$", "AR"),
57 new Lang("^Chinese$|^Mandarin$", "ZH"),
58 new Lang("^Croation$", "HR"),
59 new Lang("^Czech$", "CS"),
60 new Lang("^Dutch$", "NL"),
61 new Lang("^English$", "EN"),
62 new Lang("^Finnish$", "FI"),
63 new Lang("^French$", "FR"),
64 new Lang("^Hebrew$", "HE"),
65 new Lang("^Hindi$", "HI"),
66 new Lang("^Icelandic$", "IS"),
67 new Lang("^Irish$", "GA"),
68 new Lang("^Japanese$", "JA"),
69 new Lang("^Korean$", "KO"),
70 new Lang("^Kurdish$", "KU"),
71 new Lang("^Lithuanian$", "LT"),
72 new Lang("^Malay$", "MS"),
73 new Lang("^Maori$", "MI"),
74 new Lang("^Mongolian$", "MN"),
75 new Lang("^Norwegian$", "NO"),
76 new Lang("^Persian$", "FA"),
77 new Lang("^Portuguese$", "PT"),
78 new Lang("^Romanian$", "RO"),
79 new Lang("^Russian$", "RU"),
80 new Lang("^Sanskrit$", "SA"),
81 new Lang("^Serbian$", "SR"),
82 new Lang("^Somali$", "SO"),
83 new Lang("^Sudanese$", "SU"),
84 new Lang("^Swedish$", "SV"),
85 new Lang("^Tajik$", "TG"),
86 new Lang("^Thai$", "TH"),
87 new Lang("^Tibetan$", "BO"),
88 new Lang("^Turkish$", "TR"),
89 new Lang("^Ukranian$", "UK"),
90 new Lang("^Vietnamese$", "VI"),
91 new Lang("^Welsh$", "CY"),
92 new Lang("^Yiddish$", "YI"),
93 new Lang("^Zulu$", "ZU"),*/
96 for (final Lang lang1 : langs1) {
97 for (final Lang lang2 : langs2) {
98 if (lang1.nameRegex.equals(lang2.nameRegex)) {
103 Lang nonEnglish = null;
104 if (lang2.isoCode.equals("EN")) {
108 if (lang1.isoCode.equals("EN")) {
112 assert nonEnglish != null;
114 final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode);
115 System.out.println("building dictFile: " + dictFile);
116 DictionaryBuilder.main(new String[] {
117 String.format("--dictOut=%s", dictFile),
118 String.format("--lang1=%s", lang1.isoCode),
119 String.format("--lang2=%s", lang2.isoCode),
120 String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode),
122 "--input2=" + INPUTS + "wikiSplit/" + nonEnglish.wikiSplit,
123 "--input2Name=enwiktionary." + nonEnglish.wikiSplit,
124 "--input2Format=enwiktionary",
125 "--input2LangPattern=" + nonEnglish.nameRegex,
126 "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(),
127 "--input2EnIndex=" + enIndex,
129 "--input3=" + INPUTS + "wikiSplit/english.data",
130 "--input3Name=enwiktionary.english",
131 "--input3Format=enwiktionary",
132 "--input3LangPattern=" + nonEnglish.nameRegex,
133 "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(),
134 "--input3EnIndex=" + enIndex,
138 // Print the entries for diffing.
139 final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
140 final Dictionary dict = new Dictionary(raf);
141 final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
142 final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
143 Collections.sort(sorted);
144 for (final PairEntry pairEntry : sorted) {
145 textOut.println(pairEntry.getRawText(false));
153 DictionaryBuilder.main(new String[] {
154 "--dictOut=" + OUTPUTS + "DE-EN_chemnitz.quickdic",
157 "--dictInfo=@" + INPUTS + "de-en_chemnitz.info",
159 "--input1=" + INPUTS + "de-en_chemnitz.txt",
160 "--input1Name=chemnitz",
161 "--input1Charset=UTF8",
162 "--input1Format=chemnitz",
165 DictionaryBuilder.main(new String[] {
166 "--dictOut=" + OUTPUTS + "de-en_all.quickdic",
169 "--dictInfo=@" + INPUTS + "de-en_all.info",
171 "--input2=" + INPUTS + "de-en_chemnitz.txt",
172 "--input2Name=dictcc",
173 "--input2Charset=UTF8",
174 "--input2Format=chemnitz",
176 "--input3=" + INPUTS + "/copyrighted/de-en_dictcc.txt",
177 "--input3Name=dictcc",
178 "--input3Charset=UTF8",
179 "--input3Format=dictcc",