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.LinkedHashMap;
23 import java.util.List;
26 import junit.framework.TestCase;
28 public class DictionaryBuilderMain extends TestCase {
30 static final String INPUTS = "../DictionaryData/inputs/";
31 static final String STOPLISTS = "../DictionaryData/inputs/stoplists/";
32 static final String OUTPUTS = "../DictionaryData/outputs/";
34 public static void main(final String[] args) throws Exception {
36 final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(Language.isoCodeToWikiName);
37 isoToWikiName.remove("EN");
38 isoToWikiName.remove("DE");
40 final Map<String,String> isoToDedication = new LinkedHashMap<String, String>();
41 isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
42 isoToDedication.put("HR", "Croation dictionary dedicated to Ines Viskic and Miro Kresonja.");
43 isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
44 // German handled in file.
45 isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
46 isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe! Ti amo!");
47 isoToDedication.put("JA", "Japanese dictionary dedicated to Akane Watanabe.");
48 isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
49 isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
50 isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
51 isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
52 isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
53 isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
54 isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
56 final Map<String,String> isoToStoplist = new LinkedHashMap<String, String>();
57 isoToStoplist.put("DE", "de.txt");
58 isoToStoplist.put("EN", "en.txt");
59 isoToStoplist.put("ES", "es.txt");
60 isoToStoplist.put("IT", "it.txt");
61 isoToStoplist.put("FR", "fr.txt");
63 final Map<String,String> isoToRegex = new LinkedHashMap<String, String>();
64 isoToRegex.put("ZH", ".*Chinese.*|.*Mandarin.*|.*Cantonese.*");
67 isoToWikiName.clear();
68 for (final String foreignIso : isoToWikiName.keySet()) {
69 if (foreignIso.equals("GA")) {
76 final String dictFile = String.format(OUTPUTS + "/EN-%s_enwiktionary.quickdic", foreignIso);
77 System.out.println("building dictFile: " + dictFile);
79 if (!isoToStoplist.containsKey(foreignIso)) {
80 isoToStoplist.put(foreignIso, "empty.txt");
82 if (!isoToDedication.containsKey(foreignIso)) {
83 isoToDedication.put(foreignIso, "");
85 if (!isoToRegex.containsKey(foreignIso)) {
86 isoToRegex.put(foreignIso, ".*" + isoToWikiName.get(foreignIso) + ".*");
89 DictionaryBuilder.main(new String[] {
90 String.format("--dictOut=%s", dictFile),
91 String.format("--lang1=EN"),
92 String.format("--lang2=%s", foreignIso),
93 String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
94 String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
95 String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary. %s", foreignIso, isoToDedication.get(foreignIso)),
97 "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
98 "--input2Name=enwiktionary." + foreignIso,
99 "--input2Format=enwiktionary",
100 "--input2LangPattern=" + isoToRegex.get(foreignIso),
101 "--input2LangCodePattern=" + foreignIso.toLowerCase(),
104 "--input3=" + INPUTS + "enWikiSplit/EN.data",
105 "--input3Name=enwiktionary.english",
106 "--input3Format=enwiktionary",
107 "--input3LangPattern=" + isoToRegex.get(foreignIso),
108 "--input3LangCodePattern=" + foreignIso.toLowerCase(),
113 // Print the entries for diffing.
114 final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
115 final Dictionary dict = new Dictionary(raf);
116 final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
117 final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
118 Collections.sort(sorted);
119 for (final PairEntry pairEntry : sorted) {
120 textOut.println(pairEntry.getRawText(false));
127 DictionaryBuilder.main(new String[] {
128 "--dictOut=" + OUTPUTS + "DE-EN_chemnitz_enwiktionary.quickdic",
131 String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("DE")),
132 String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
133 "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
135 "--input1=" + INPUTS + "de-en_chemnitz.txt",
136 "--input1Name=chemnitz",
137 "--input1Charset=UTF8",
138 "--input1Format=chemnitz",
140 "--input2=" + INPUTS + "enWikiSplit/DE.data",
141 "--input2Name=enwiktionary.DE",
142 "--input2Format=enwiktionary",
143 "--input2LangPattern=" + isoToRegex.get("DE"),
144 "--input2LangCodePattern=de",
147 "--input3=" + INPUTS + "enWikiSplit/EN.data",
148 "--input3Name=enwiktionary.english",
149 "--input3Format=enwiktionary",
150 "--input3LangPattern=" + isoToRegex.get("DE"),
151 "--input3LangCodePattern=de",