]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderMain.java
Printint dictionaries for diff.
[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.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import java.io.RandomAccessFile;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import junit.framework.TestCase;
30
31 public class DictionaryBuilderMain extends TestCase {
32   
33   static final String INPUTS = "../DictionaryData/inputs/";
34   static final String STOPLISTS = "../DictionaryData/inputs/stoplists/";
35   static final String OUTPUTS = "../DictionaryData/outputs/";
36     
37   public static void main(final String[] args) throws Exception {
38     
39     final Map<String,String> isoToWikiName = new LinkedHashMap<String, String>(Language.isoCodeToWikiName);
40     isoToWikiName.remove("EN");
41     isoToWikiName.remove("DE");
42
43     final Map<String,String>  isoToDedication = new LinkedHashMap<String, String>();
44     isoToDedication.put("AF", "Afrikaans dictionary dedicated to Heiko and Mariëtte Horn.");
45     isoToDedication.put("HR", "Croation dictionary dedicated to Ines Viskic and Miro Kresonja.");
46     isoToDedication.put("NL", "Dutch dictionary dedicated to Mike LeBeau.");
47     // German handled in file.
48     isoToDedication.put("EL", "Greek dictionary dedicated to Noah Egge.");
49     isoToDedication.put("IT", "Italian dictionary dedicated to Carolina Tropini, my favorite stardust in the whole universe!  Ti amo!");
50     isoToDedication.put("KO", "Korean dictionary dedicated to Ande Elwood--fall fashion und Fernsehturms!");
51     isoToDedication.put("PT", "Portuguese dictionary dedicated to Carlos Melo, one Tough Mudder.");
52     isoToDedication.put("RO", "Romanian dictionary dedicated to Radu Teodorescu.");
53     isoToDedication.put("RU", "Russian dictionary dedicated to Maxim Aronin--best friend always!.");
54     isoToDedication.put("SR", "Serbian dictionary dedicated to Filip Crnogorac--thanks for the honey.");
55     isoToDedication.put("ES", "Spanish dictionary made especially for Carolina Tropini! <3 XoXoXXXXX!");
56     isoToDedication.put("SV", "Swedish dictionary dedicated to Kajsa Palmblad--björn kramar!");
57
58     final Map<String,String>  isoToStoplist = new LinkedHashMap<String, String>();
59     isoToStoplist.put("DE", "de.txt");
60     isoToStoplist.put("EN", "en.txt");
61     isoToStoplist.put("ES", "es.txt");
62     isoToStoplist.put("IT", "it.txt");
63     isoToStoplist.put("FR", "fr.txt");
64
65     final Map<String,String>  isoToRegex = new LinkedHashMap<String, String>();
66     isoToRegex.put("ZH", "Chinese|Mandarin|Cantonese");
67     
68 //    isoToWikiName.keySet().retainAll(Arrays.asList("UK", "HR", "FI"));
69     boolean go = true; 
70     isoToWikiName.clear();
71     for (final String foreignIso : isoToWikiName.keySet()) {
72       if (foreignIso.equals("SV")) {
73         go = true;
74       }
75       if (!go) {
76         continue;
77       }
78
79         final String dictFile = String.format(OUTPUTS + "/EN-%s_enwiktionary.quickdic", foreignIso);
80         System.out.println("building dictFile: " + dictFile);
81         
82         if (!isoToStoplist.containsKey(foreignIso)) {
83           isoToStoplist.put(foreignIso, "empty.txt");
84         }
85         if (!isoToDedication.containsKey(foreignIso)) {
86           isoToDedication.put(foreignIso, "");
87         }
88         if (!isoToRegex.containsKey(foreignIso)) {
89           isoToRegex.put(foreignIso, isoToWikiName.get(foreignIso));
90         }
91   
92         DictionaryBuilder.main(new String[] {
93             String.format("--dictOut=%s", dictFile),
94             String.format("--lang1=EN"),
95             String.format("--lang2=%s", foreignIso),
96             String.format("--lang1Stoplist=%s", STOPLISTS + isoToStoplist.get("EN")),
97             String.format("--lang2Stoplist=%s", STOPLISTS + isoToStoplist.get(foreignIso)),
98             String.format("--dictInfo=(EN)Wikitionary-based EN-%s dictionary.  %s", foreignIso, isoToDedication.get(foreignIso)),
99
100             "--input2=" + INPUTS + "enWikiSplit/" + foreignIso + ".data",
101             "--input2Name=enwiktionary." + foreignIso,
102             "--input2Format=enwiktionary",
103             "--input2LangPattern=" + isoToRegex.get(foreignIso),
104             "--input2LangCodePattern=" + foreignIso.toLowerCase(),
105             "--input2EnIndex=1",
106
107             "--input3=" + INPUTS + "enWikiSplit/EN.data",
108             "--input3Name=enwiktionary.english",
109             "--input3Format=enwiktionary",
110             "--input3LangPattern=" + isoToRegex.get(foreignIso),
111             "--input3LangCodePattern=" + foreignIso.toLowerCase(),
112             "--input3EnIndex=1",
113
114         });
115         
116         // Print the entries for diffing.
117         printToText(dictFile);
118
119     }  // foreignIso
120
121     final String dictFile = OUTPUTS + "DE-EN_chemnitz_enwiktionary.quickdic"; 
122     DictionaryBuilder.main(new String[] {
123         "--dictOut=" + dictFile,
124         "--lang1=DE",
125         "--lang2=EN",
126         String.format("--lang1Stoplist=%s", STOPLISTS + "de.txt"),
127         String.format("--lang2Stoplist=%s", STOPLISTS + "en.txt"),
128         "--dictInfo=@" + INPUTS + "de-en_chemnitz_enwiktionary.info",
129
130         "--input4=" + INPUTS + "de-en_chemnitz.txt",
131         "--input4Name=chemnitz",
132         "--input4Charset=UTF8",
133         "--input4Format=chemnitz",
134         
135         "--input2=" + INPUTS + "enWikiSplit/DE.data",
136         "--input2Name=enwiktionary.DE",
137         "--input2Format=enwiktionary",
138         "--input2LangPattern=German",
139         "--input2LangCodePattern=de",
140         "--input2EnIndex=2",
141
142         "--input3=" + INPUTS + "enWikiSplit/EN.data",
143         "--input3Name=enwiktionary.english",
144         "--input3Format=enwiktionary",
145         "--input3LangPattern=German",
146         "--input3LangCodePattern=de",
147         "--input3EnIndex=2",
148     });
149     printToText(dictFile);
150     
151   }
152   
153   static void printToText(final String dictFile) throws IOException {
154     final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
155     final Dictionary dict = new Dictionary(raf);
156     final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
157     final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
158     Collections.sort(sorted);
159     for (final PairEntry pairEntry : sorted) {
160       textOut.println(pairEntry.getRawText(false));
161     }
162     textOut.close();
163     raf.close();
164   }
165   
166 }