]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
Initialism, changes in regex matching.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / DictionaryBuilderMain.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.io.File;
18 import java.io.PrintWriter;
19 import java.io.RandomAccessFile;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import junit.framework.TestCase;
28
29 public class DictionaryBuilderMain extends TestCase {
30   
31   static final String INPUTS = "../DictionaryData/inputs/";
32   static final String STOPLISTS = "../DictionaryData/inputs/stoplists/";
33   static final String OUTPUTS = "../DictionaryData/outputs/";
34     
35   public static void main(final String[] args) throws Exception {
36     
37     final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(Language.isoCodeToWikiName);
38     isoToWikiName.remove("EN");
39     isoToWikiName.remove("DE");
40
41     final Map<String,String>  isoToDedication = new LinkedHashMap<String, String>();
42     isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
43     isoToDedication.put("HR", "Croation dictionary dedicated to Ines Viskic and Miro Kresonja.");
44     isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
45     // German handled in file.
46     isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
47     isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe!  Ti amo!");
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!");
55
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");
62
63     final Map<String,String>  isoToRegex = new LinkedHashMap<String, String>();
64     isoToRegex.put("ZH", "Chinese|Mandarin|Cantonese");
65     
66     isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
67     
68     boolean go = true; 
69 //    isoToWikiName.clear();
70     for (final String foreignIso : isoToWikiName.keySet()) {
71       if (foreignIso.equals("SV")) {
72         go = true;
73       }
74       if (!go) {
75         continue;
76       }
77
78         final String dictFile = String.format(OUTPUTS + "/EN-%s_enwiktionary.quickdic", foreignIso);
79         System.out.println("building dictFile: " + dictFile);
80         
81         if (!isoToStoplist.containsKey(foreignIso)) {
82           isoToStoplist.put(foreignIso, "empty.txt");
83         }
84         if (!isoToDedication.containsKey(foreignIso)) {
85           isoToDedication.put(foreignIso, "");
86         }
87         if (!isoToRegex.containsKey(foreignIso)) {
88           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
89         }
90   
91         DictionaryBuilder.main(new String[] {
92             String.format("--dictOut=%s", dictFile),
93             String.format("--lang1=EN"),
94             String.format("--lang2=%s", foreignIso),
95             String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
96             String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
97             String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary.  %s", foreignIso, isoToDedication.get(foreignIso)),
98
99             "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
100             "--input2Name=enwiktionary." + foreignIso,
101             "--input2Format=enwiktionary",
102             "--input2LangPattern=" + isoToRegex.get(foreignIso),
103             "--input2LangCodePattern=" + foreignIso.toLowerCase(),
104             "--input2EnIndex=1",
105
106             "--input3=" + INPUTS + "enWikiSplit/EN.data",
107             "--input3Name=enwiktionary.english",
108             "--input3Format=enwiktionary",
109             "--input3LangPattern=" + isoToRegex.get(foreignIso),
110             "--input3LangCodePattern=" + foreignIso.toLowerCase(),
111             "--input3EnIndex=1",
112
113         });
114         
115         // Print the entries for diffing.
116         final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
117         final Dictionary dict = new Dictionary(raf);
118         final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
119         final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
120         Collections.sort(sorted);
121         for (final PairEntry pairEntry : sorted) {
122           textOut.println(pairEntry.getRawText(false));
123         }
124         textOut.close();
125         raf.close();
126
127     }  // foreignIso
128
129     DictionaryBuilder.main(new String[] {
130         "--dictOut=" + OUTPUTS + "DE-EN_chemnitz_enwiktionary.quickdic",
131         "--lang1=DE",
132         "--lang2=EN",
133         String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("DE")),
134         String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
135         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
136
137         "--input1=" + INPUTS + "de-en_chemnitz.txt",
138         "--input1Name=chemnitz",
139         "--input1Charset=UTF8",
140         "--input1Format=chemnitz",
141         
142         "--input2=" + INPUTS + "enWikiSplit/DE.data",
143         "--input2Name=enwiktionary.DE",
144         "--input2Format=enwiktionary",
145         "--input2LangPattern=" + isoToRegex.get("DE"),
146         "--input2LangCodePattern=de",
147         "--input2EnIndex=2",
148
149         "--input3=" + INPUTS + "enWikiSplit/EN.data",
150         "--input3Name=enwiktionary.english",
151         "--input3Format=enwiktionary",
152         "--input3LangPattern=" + isoToRegex.get("DE"),
153         "--input3LangCodePattern=de",
154         "--input3EnIndex=2",
155         
156     });
157
158   }
159   
160 }