+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package com.hughes.android.dictionary.engine;
import java.io.File;
public class DictionaryBuilderMain extends TestCase {
+ static final String INPUTS = "../DictionaryData/inputs/";
+ static final String STOPLISTS = "../DictionaryData/inputs/stoplists/";
+ static final String OUTPUTS = "../DictionaryData/outputs/";
+
static class Lang {
final String nameRegex;
- final String code;
- public Lang(String nameRegex, String code) {
+ final String isoCode;
+ final String wikiSplit;
+ final String stoplistFile;
+ public Lang(String nameRegex, String code, final String wikiSplit, final String stoplistFile) {
this.nameRegex = nameRegex;
- this.code = code;
+ this.isoCode = code;
+ this.wikiSplit = wikiSplit;
+ this.stoplistFile = stoplistFile;
}
}
public static void main(final String[] args) throws Exception {
- DictionaryBuilder.main(new String[] {
- "--dictOut=dictOutputs/DE-EN_chemnitz.quickdic",
- "--lang1=DE",
- "--lang2=EN",
- "--dictInfo=@dictInputs/de-en_chemnitz.info",
-
- "--input1=dictInputs/de-en_chemnitz.txt",
- "--input1Name=chemnitz",
- "--input1Charset=UTF8",
- "--input1Format=chemnitz",
- });
-
Lang[] langs1 = new Lang[] {
- new Lang("^English$", "EN"),
- new Lang("^German$", "DE"),
+ new Lang("^English$", "EN", null, "en.txt"),
};
Lang[] langs2 = new Lang[] {
- new Lang("^Italian$", "IT"),
+ new Lang("^.*Italian.*$", "IT", "italian.data", "it.txt"),
+ new Lang("^.*French.*$", "FR", "french.data", "empty.txt"),
+ new Lang("^.*Spanish.*$", "ES", "spanish.data", "empty.txt"),
+ new Lang("^.*Greek.*$", "EL", "greek.data", "empty.txt"),
+ new Lang("^.*Japanese.*$", "JA", "japanese.data", "empty.txt"),
+ new Lang("^.*Chinese.*$|^.*Mandarin.*$", "ZH", "mandarin.data", "empty.txt"),
+ /*
new Lang("^German$", "DE"),
new Lang("^Afrikaans$", "AF"),
new Lang("^Armenian$", "HY"),
new Lang("^Arabic$", "AR"),
- new Lang("^Chinese$|^Mandarin$", "ZH"),
new Lang("^Croation$", "HR"),
new Lang("^Czech$", "CS"),
new Lang("^Dutch$", "NL"),
new Lang("^English$", "EN"),
new Lang("^Finnish$", "FI"),
- new Lang("^French$", "FR"),
- new Lang("^Greek$", "EL"),
new Lang("^Hebrew$", "HE"),
new Lang("^Hindi$", "HI"),
new Lang("^Icelandic$", "IS"),
new Lang("^Irish$", "GA"),
- new Lang("^Japanese$", "JA"),
new Lang("^Korean$", "KO"),
new Lang("^Kurdish$", "KU"),
new Lang("^Lithuanian$", "LT"),
new Lang("^Sanskrit$", "SA"),
new Lang("^Serbian$", "SR"),
new Lang("^Somali$", "SO"),
- new Lang("^Spanish$", "ES"),
new Lang("^Sudanese$", "SU"),
new Lang("^Swedish$", "SV"),
new Lang("^Tajik$", "TG"),
new Lang("^Vietnamese$", "VI"),
new Lang("^Welsh$", "CY"),
new Lang("^Yiddish$", "YI"),
- new Lang("^Zulu$", "ZU"),
+ new Lang("^Zulu$", "ZU"),*/
};
for (final Lang lang1 : langs1) {
}
int enIndex = -1;
- if (lang2.code.equals("EN")) {
+ Lang nonEnglish = null;
+ if (lang2.isoCode.equals("EN")) {
enIndex = 2;
+ nonEnglish = lang1;
}
- if (lang1.code.equals("EN")) {
+ if (lang1.isoCode.equals("EN")) {
enIndex = 1;
+ nonEnglish = lang2;
}
+ assert nonEnglish != null;
- final String dictFile = String.format("dictOutputs/%s-%s_enwiktionary.quickdic", lang1.code, lang2.code);
+ final String dictFile = String.format(OUTPUTS + "/%s-%s_enwiktionary.quickdic", lang1.isoCode, lang2.isoCode);
System.out.println("building dictFile: " + dictFile);
DictionaryBuilder.main(new String[] {
String.format("--dictOut=%s", dictFile),
- String.format("--lang1=%s", lang1.code),
- String.format("--lang2=%s", lang2.code),
- String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.code, lang2.code),
-
- "--input1=dictInputs/enwiktionary-20101015-pages-articles",
- "--input1Name=enwiktionary",
- "--input1Format=enwiktionary",
- String.format("--input1TranslationPattern1=%s", lang1.nameRegex),
- String.format("--input1TranslationPattern2=%s", lang2.nameRegex),
- String.format("--input1EnIndex=%d", enIndex),
+ String.format("--lang1=%s", lang1.isoCode),
+ String.format("--lang2=%s", lang2.isoCode),
+ String.format("--lang1Stoplist=%s", STOPLISTS + lang1.stoplistFile),
+ String.format("--lang2Stoplist=%s", STOPLISTS + lang2.stoplistFile),
+ String.format("--dictInfo=(EN)Wikitionary-based %s-%s dictionary", lang1.isoCode, lang2.isoCode),
+
+ "--input2=" + INPUTS + "enWikiSplit/" + nonEnglish.wikiSplit,
+ "--input2Name=enwiktionary." + nonEnglish.wikiSplit,
+ "--input2Format=enwiktionary",
+ "--input2LangPattern=" + nonEnglish.nameRegex,
+ "--input2LangCodePattern=" + nonEnglish.isoCode.toLowerCase(),
+ "--input2EnIndex=" + enIndex,
+
+ "--input3=" + INPUTS + "enWikiSplit/english.data",
+ "--input3Name=enwiktionary.english",
+ "--input3Format=enwiktionary",
+ "--input3LangPattern=" + nonEnglish.nameRegex,
+ "--input3LangCodePattern=" + (enIndex == 1 ? lang2.isoCode : lang1.isoCode).toLowerCase(),
+ "--input3EnIndex=" + enIndex,
+
});
// Print the entries for diffing.
final RandomAccessFile raf = new RandomAccessFile(new File(dictFile), "r");
final Dictionary dict = new Dictionary(raf);
- final PrintWriter textOut = new PrintWriter(new File(dictFile + ".txt"));
+ final PrintWriter textOut = new PrintWriter(new File(dictFile + ".text"));
final List<PairEntry> sorted = new ArrayList<PairEntry>(dict.pairEntries);
Collections.sort(sorted);
for (final PairEntry pairEntry : sorted) {
} // langs1
DictionaryBuilder.main(new String[] {
- "--dictOut=dictOutputs/de-en_all.quickdic",
+ "--dictOut=" + OUTPUTS + "DE-EN_chemnitz.quickdic",
"--lang1=DE",
"--lang2=EN",
- "--dictInfo=@dictInputs/de-en_all.info",
+ "--dictInfo=@" + INPUTS + "de-en_chemnitz.info",
- "--input2=dictInputs/de-en_chemnitz.txt",
+ "--input1=" + INPUTS + "de-en_chemnitz.txt",
+ "--input1Name=chemnitz",
+ "--input1Charset=UTF8",
+ "--input1Format=chemnitz",
+ });
+
+ DictionaryBuilder.main(new String[] {
+ "--dictOut=" + OUTPUTS + "de-en_all.quickdic",
+ "--lang1=DE",
+ "--lang2=EN",
+ "--dictInfo=@" + INPUTS + "de-en_all.info",
+
+ "--input2=" + INPUTS + "de-en_chemnitz.txt",
"--input2Name=dictcc",
"--input2Charset=UTF8",
"--input2Format=chemnitz",
- "--input3=dictInputs/de-en_dictcc.txt",
+ "--input3=" + INPUTS + "/NONFREE/de-en_dictcc.txt",
"--input3Name=dictcc",
"--input3Charset=UTF8",
"--input3Format=dictcc",
- "--input1=dictInputs/enwiktionary-20101015-pages-articles",
- "--input1Name=enwiktionary",
- "--input1Format=enwiktionary",
- "--input1TranslationPattern1=^German$",
- "--input1TranslationPattern2=^English$",
- "--input1EnIndex=2",
-
+ // TODO: wiktionary
});
}