]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
Fixed {{infl}}
[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     boolean go = true; 
68     isoToWikiName.clear();
69     for (final String foreignIso : isoToWikiName.keySet()) {
70       if (foreignIso.equals("SV")) {
71         go = true;
72       }
73       if (!go) {
74         continue;
75       }
76
77         final String dictFile = String.format(OUTPUTS + "/EN-%s_enwiktionary.quickdic", foreignIso);
78         System.out.println("building dictFile: " + dictFile);
79         
80         if (!isoToStoplist.containsKey(foreignIso)) {
81           isoToStoplist.put(foreignIso, "empty.txt");
82         }
83         if (!isoToDedication.containsKey(foreignIso)) {
84           isoToDedication.put(foreignIso, "");
85         }
86         if (!isoToRegex.containsKey(foreignIso)) {
87           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
88         }
89   
90         DictionaryBuilder.main(new String[] {
91             String.format("--dictOut=%s", dictFile),
92             String.format("--lang1=EN"),
93             String.format("--lang2=%s", foreignIso),
94             String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
95             String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
96             String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary.  %s", foreignIso, isoToDedication.get(foreignIso)),
97
98             "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
99             "--input2Name=enwiktionary." + foreignIso,
100             "--input2Format=enwiktionary",
101             "--input2LangPattern=" + isoToRegex.get(foreignIso),
102             "--input2LangCodePattern=" + foreignIso.toLowerCase(),
103             "--input2EnIndex=1",
104
105             "--input3=" + INPUTS + "enWikiSplit/EN.data",
106             "--input3Name=enwiktionary.english",
107             "--input3Format=enwiktionary",
108             "--input3LangPattern=" + isoToRegex.get(foreignIso),
109             "--input3LangCodePattern=" + foreignIso.toLowerCase(),
110             "--input3EnIndex=1",
111
112         });
113         
114         // Print the entries for diffing.
115         final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
116         final Dictionary dict = new Dictionary(raf);
117         final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
118         final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
119         Collections.sort(sorted);
120         for (final PairEntry pairEntry : sorted) {
121           textOut.println(pairEntry.getRawText(false));
122         }
123         textOut.close();
124         raf.close();
125
126     }  // foreignIso
127
128     DictionaryBuilder.main(new String[] {
129         "--dictOut=" + OUTPUTS + "DE-EN_chemnitz_enwiktionary.quickdic",
130         "--lang1=DE",
131         "--lang2=EN",
132         String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
133         String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
134         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
135
136         "--input4=" + INPUTS + "de-en_chemnitz.txt",
137         "--input4Name=chemnitz",
138         "--input4Charset=UTF8",
139         "--input4Format=chemnitz",
140         
141         "--input2=" + INPUTS + "enWikiSplit/DE.data",
142         "--input2Name=enwiktionary.DE",
143         "--input2Format=enwiktionary",
144         "--input2LangPattern=German",
145         "--input2LangCodePattern=de",
146         "--input2EnIndex=2",
147
148         "--input3=" + INPUTS + "enWikiSplit/EN.data",
149         "--input3Name=enwiktionary.english",
150         "--input3Format=enwiktionary",
151         "--input3LangPattern=German",
152         "--input3LangCodePattern=de",
153         "--input3EnIndex=2",
154         
155     });
156
157   }
158   
159 }