X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fparser%2Fwiktionary%2FEnFunctionCallbacks.java;h=3161f4abeec1d832f32b63a98f2623064e22ba05;hb=752c81f1f8ec816865611477896093d81a77f90a;hp=5593ffd8bc31826ef782853eebfb37a2d8876f9b;hpb=90247c9eb280bd2b55f9b2b2816bad03a0821a7f;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/parser/wiktionary/EnFunctionCallbacks.java b/src/com/hughes/android/dictionary/parser/wiktionary/EnFunctionCallbacks.java index 5593ffd..3161f4a 100644 --- a/src/com/hughes/android/dictionary/parser/wiktionary/EnFunctionCallbacks.java +++ b/src/com/hughes/android/dictionary/parser/wiktionary/EnFunctionCallbacks.java @@ -14,6 +14,14 @@ package com.hughes.android.dictionary.parser.wiktionary; +import com.hughes.android.dictionary.engine.EntryTypeName; +import com.hughes.android.dictionary.engine.IndexBuilder; +import com.hughes.android.dictionary.parser.WikiTokenizer; +import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.AppendAndIndexWikiCallback; +import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.NameAndArgs; +import com.hughes.util.ListUtil; +import com.hughes.util.MapUtil; + import java.util.Arrays; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -22,18 +30,93 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import com.hughes.android.dictionary.engine.EntryTypeName; -import com.hughes.android.dictionary.engine.IndexBuilder; -import com.hughes.android.dictionary.parser.WikiTokenizer; -import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.AppendAndIndexWikiCallback; -import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.NameAndArgs; -import com.hughes.util.ListUtil; - class EnFunctionCallbacks { static final Map> DEFAULT = new LinkedHashMap>(); - + + static void addGenericCallbacks(Map> callbacks) { + FunctionCallback callback = new Gender(); + callbacks.put("m", callback); + callbacks.put("f", callback); + callbacks.put("n", callback); + callbacks.put("p", callback); + callbacks.put("g", callback); + + callback = new EncodingCallback(); + Set encodings = new LinkedHashSet(Arrays.asList( + "IPA", "IPAchar", // Not really encodings, but it works. + "zh-ts", "zh-tsp", + "sd-Arab", "ku-Arab", "Arab", "unicode", "Laoo", "ur-Arab", "Thai", + "fa-Arab", "Khmr", "Cyrl", "ug-Arab", "ko-inline", + "Jpan", "Kore", "Hebr", "rfscript", "Beng", "Mong", "Knda", "Cyrs", + "yue-tsj", "Mlym", "Tfng", "Grek", "yue-yue-j")); + for (final String encoding : encodings) { + callbacks.put(encoding, callback); + } + + callback = new Ignore(); + callbacks.put("trreq", callback); + callbacks.put("t-image", callback); + callbacks.put("defn", callback); + callbacks.put("rfdef", callback); + callbacks.put("rfdate", callback); + callbacks.put("rfex", callback); + callbacks.put("rfquote", callback); + callbacks.put("attention", callback); + callbacks.put("zh-attention", callback); + callbacks.put("top2", callback); + callbacks.put("mid2", callback); + callbacks.put("top3", callback); + callbacks.put("mid3", callback); + callbacks.put("bottom", callback); + callbacks.put("rel-mid", callback); + callbacks.put("rel-mid3", callback); + callbacks.put("rel-mid4", callback); + callbacks.put("rel-bottom", callback); + + callback = new AppendName(); + callbacks.put("...", callback); + + callbacks.put("qualifier", new QualifierCallback()); + callbacks.put("italbrac", new italbrac()); + callbacks.put("gloss", new gloss()); + callbacks.put("not used", new not_used()); + callbacks.put("wikipedia", new wikipedia()); + + final it_conj it_conj_cb = new it_conj(); + callbacks.put("it-conj", it_conj_cb); + callbacks.put("it-conj-are", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-arsi", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-care", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-carsi", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-ciare", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-ciarsi", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-iare", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-iarsi", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-iare-b", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-iarsi-b", new it_conj_are(it_conj_cb)); + callbacks.put("it-conj-ire", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-irsi", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-ire-b", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-irsi-b", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-cire", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-cirsi", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-ire", new it_conj_ire(it_conj_cb)); + callbacks.put("it-conj-ere", new it_conj_ere(it_conj_cb)); + callbacks.put("it-conj-ersi", new it_conj_ere(it_conj_cb)); + callbacks.put("it-conj-urre", new it_conj_urre(it_conj_cb)); + callbacks.put("it-conj-ursi", new it_conj_urre(it_conj_cb)); + callbacks.put("it-conj-fare", new it_conj_fare(it_conj_cb)); + + + //"{{it-conj-fare|putre|avere}}\n" + + + + } + static { + addGenericCallbacks(DEFAULT); + FunctionCallback callback = new TranslationCallback(); DEFAULT.put("t", callback); DEFAULT.put("t+", callback); @@ -41,41 +124,11 @@ class EnFunctionCallbacks { DEFAULT.put("tø", callback); DEFAULT.put("apdx-t", callback); - callback = new EncodingCallback(); - Set encodings = new LinkedHashSet(Arrays.asList( - "zh-ts", "zh-tsp", - "sd-Arab", "ku-Arab", "Arab", "unicode", "Laoo", "ur-Arab", "Thai", - "fa-Arab", "Khmr", "Cyrl", "IPAchar", "ug-Arab", "ko-inline", - "Jpan", "Kore", "Hebr", "rfscript", "Beng", "Mong", "Knda", "Cyrs", - "yue-tsj", "Mlym", "Tfng", "Grek", "yue-yue-j")); - for (final String encoding : encodings) { - DEFAULT.put(encoding, callback); - } - callback = new l_term(); DEFAULT.put("l", callback); DEFAULT.put("term", callback); - callback = new Gender(); - DEFAULT.put("m", callback); - DEFAULT.put("f", callback); - DEFAULT.put("n", callback); - DEFAULT.put("p", callback); - DEFAULT.put("g", callback); - - callback = new AppendArg0(); - - callback = new Ignore(); - DEFAULT.put("trreq", callback); - DEFAULT.put("t-image", callback); - DEFAULT.put("defn", callback); - DEFAULT.put("rfdef", callback); - DEFAULT.put("rfdate", callback); - DEFAULT.put("rfex", callback); - DEFAULT.put("rfquote", callback); - DEFAULT.put("attention", callback); - DEFAULT.put("zh-attention", callback); - + //callback = new AppendArg0(); callback = new FormOf(); DEFAULT.put("form of", callback); @@ -96,15 +149,6 @@ class EnFunctionCallbacks { callback = new InflOrHead(); DEFAULT.put("infl", callback); DEFAULT.put("head", callback); - - callback = new AppendName(); - DEFAULT.put("...", callback); - - DEFAULT.put("qualifier", new QualifierCallback()); - DEFAULT.put("italbrac", new italbrac()); - DEFAULT.put("gloss", new gloss()); - DEFAULT.put("not used", new not_used()); - DEFAULT.put("wikipedia", new wikipedia()); } static final NameAndArgs NAME_AND_ARGS = new NameAndArgs(); @@ -173,12 +217,12 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class QualifierCallback implements FunctionCallback { + static final class QualifierCallback implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { if (args.size() != 1 || !namedArgs.isEmpty()) { EnParser.LOG.warning("weird qualifier: "); return false; @@ -193,20 +237,26 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class EncodingCallback implements FunctionCallback { + static final class EncodingCallback implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + //namedArgs.remove("lang"); if (!namedArgs.isEmpty()) { EnParser.LOG.warning("weird encoding: " + wikiTokenizer.token()); + return false; } if (args.size() == 0) { // Things like "{{Jpan}}" exist. return true; } + if (name.equals("IPA")) { + appendAndIndexWikiCallback.dispatch("IPA: ", null); + } + for (int i = 0; i < args.size(); ++i) { if (i > 0) { appendAndIndexWikiCallback.builder.append(", "); @@ -224,12 +274,12 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class Gender implements FunctionCallback { + static final class Gender implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { if (!namedArgs.isEmpty()) { return false; } @@ -312,7 +362,7 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class AppendArg0 implements FunctionCallback { + static final class AppendArg0 implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, @@ -337,12 +387,12 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class italbrac implements FunctionCallback { + static final class italbrac implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { if (args.size() != 1 || !namedArgs.isEmpty()) { return false; } @@ -355,12 +405,12 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class gloss implements FunctionCallback { + static final class gloss implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { if (args.size() != 1 || !namedArgs.isEmpty()) { return false; } @@ -373,24 +423,24 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class Ignore implements FunctionCallback { + static final class Ignore implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { return true; } } // ------------------------------------------------------------------ - static final class not_used implements FunctionCallback { + static final class not_used implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { appendAndIndexWikiCallback.builder.append("(not used)"); return true; } @@ -399,12 +449,12 @@ class EnFunctionCallbacks { // ------------------------------------------------------------------ - static final class AppendName implements FunctionCallback { + static final class AppendName implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { if (!args.isEmpty() || !namedArgs.isEmpty()) { return false; } @@ -460,12 +510,12 @@ class EnFunctionCallbacks { // -------------------------------------------------------------------- // -------------------------------------------------------------------- - static final class wikipedia implements FunctionCallback { + static final class wikipedia implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { namedArgs.remove("lang"); if (args.size() > 1 || !namedArgs.isEmpty()) { // Unindexed! @@ -577,6 +627,18 @@ class EnFunctionCallbacks { appendAndIndexWikiCallback.builder.append(" {").append(gender).append("}, "); appendAndIndexWikiCallback.dispatch(plural, null, null); appendAndIndexWikiCallback.builder.append(" {pl}"); + final String f = namedArgs.remove("f"); + if (f != null) { + appendAndIndexWikiCallback.builder.append(", "); + appendAndIndexWikiCallback.dispatch(f, null, null); + appendAndIndexWikiCallback.builder.append(" {f}"); + } + final String m = namedArgs.remove("f"); + if (m != null) { + appendAndIndexWikiCallback.builder.append(", "); + appendAndIndexWikiCallback.dispatch(m, null, null); + appendAndIndexWikiCallback.builder.append(" {m}"); + } parser.wordForms.add(singular); parser.wordForms.add(plural); if (!namedArgs.isEmpty() || args.size() > 4) { @@ -587,16 +649,475 @@ class EnFunctionCallbacks { } static { - DEFAULT.put("it-proper noun", new it_proper_noun()); + DEFAULT.put("it-proper noun", new it_proper_noun()); } - static final class it_proper_noun implements FunctionCallback { + static final class it_proper_noun implements FunctionCallback { @Override public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, final Map namedArgs, - final EnParser parser, - final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { return false; } } + + // ----------------------------------------------------------------------- + // Italian stuff + // ----------------------------------------------------------------------- + +static final class it_conj_are implements FunctionCallback { + final it_conj dest; + it_conj_are(it_conj dest) { + this.dest = dest; + } + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final String h = name.equals("it-conj-care") || name.equals("it-conj-carsi") ? "h" : ""; + final String i = name.equals("it-conj-ciare") || name.equals("it-conj-ciarsi") ? "i" : ""; + final String i2 = name.equals("it-conj-iare") || name.equals("it-conj-iarsi") ? "" : "i"; + final boolean si = name.equals("it-conj-arsi") || name.equals("it-conj-iarsi") || name.equals("it-conj-iarsi-b") || name.equals("it-conj-carsi") || name.equals("it-conj-ciarsi"); + final String root = args.get(0); + passThroughOrFillIn(namedArgs, "inf", root + i + (si ? "arsi" : "are"), false); + namedArgs.put("aux", ListUtil.get(args, 1, "")); + passThroughOrFillIn(namedArgs, "ger", root + i + "ando" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "presp", root + i + "ante"+ (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "pastp", root + i + "ato", true); + if (si) { + passThroughOrFillIn(namedArgs, "pastp2", root + i + "atosi", true); + } + final String i2b = (name.equals("it-conj-iare-b") || name.equals("it-conj-iarsi-b")) ? "" : i2; + + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList(i + "o", h + i2, i + "a", h + i2 + "amo", i + "ate", i + "ano")); + it_conj_passMood(namedArgs, "imperf", false, root, Arrays.asList(i + "avo", i + "avi", i + "ava", i + "avamo", i + "avate", i + "avano")); + it_conj_passMood(namedArgs, "prem", false, root, Arrays.asList(i + "ai", i + "asti", i + "ò", i + "ammo", i + "aste", i + "arono")); + it_conj_passMood(namedArgs, "fut", true, root, Arrays.asList(h + "erò", h + "erai", h + "erà", h + "eremo", h + "erete", h + "eranno")); + it_conj_passMood(namedArgs, "cond", true, root, Arrays.asList(h + "erei", h + "eresti", h + "erebbe", h + "eremmo", h + "ereste", h + "erebbero")); + + passThroughOrFillIn(namedArgs, "sub123s", root + h + i2, false); + passThroughOrFillIn(namedArgs, "sub1p", root + h + i2b + "amo", false); + passThroughOrFillIn(namedArgs, "sub2p", root + h + i2b + "ate", false); + passThroughOrFillIn(namedArgs, "sub3p", root + h + i2 + "no", false); + + passThroughOrFillIn(namedArgs, "impsub12s", root + i + "assi", false); + passThroughOrFillIn(namedArgs, "impsub3s", root + i + "asse", false); + passThroughOrFillIn(namedArgs, "impsub1p", root + i + "assimo", false); + passThroughOrFillIn(namedArgs, "impsub2p", root + i + "aste", false); + passThroughOrFillIn(namedArgs, "impsub3p", root + i + "assero", false); + + passThroughOrFillIn(namedArgs, "imp2s", root + i + "a" + (si ? "ti" : ""), true); + passThroughOrFillIn(namedArgs, "imp3s", (si ? "si " : "") + root + h + i2, true); + passThroughOrFillIn(namedArgs, "imp1p", root + h + i2b + "amo" + (si ? "ci" : ""), true); + passThroughOrFillIn(namedArgs, "imp2p", root + i + "ate" + (si ? "vi" : ""), true); + passThroughOrFillIn(namedArgs, "imp3p", (si ? "si " : "") + root + h + i2 + "no", true); + + return dest.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, appendAndIndexWikiCallback); + } + } + + static final class it_conj_ire implements FunctionCallback { + final it_conj dest; + it_conj_ire(it_conj dest) { + this.dest = dest; + } + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final String root = args.get(0); + final String i = name.equals("it-conj-cire") || name.equals("it-conj-cirsi") ? "i" : ""; + final boolean si = name.equals("it-conj-irsi") || name.equals("it-conj-irsi-b") || name.equals("it-conj-cirsi"); + + passThroughOrFillIn(namedArgs, "inf", root + (si ? "irsi" : "ire"), false); + namedArgs.put("aux", ListUtil.get(args, 1, "")); + passThroughOrFillIn(namedArgs, "ger", root + "endo" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "presp", root + "ente" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "pastp", root + "ito", true); + if (si) { + passThroughOrFillIn(namedArgs, "pastp2", root + "itosi", true); + } + if (!name.endsWith("-b")) { + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList(i + "o", "i", "e", "iamo", "ite", i + "ono")); + } else { + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList("isco", "isci", "isce", "iamo", "ite", "iscono")); + } + it_conj_passMood(namedArgs, "imperf", false, root, Arrays.asList("ivo", "ivi", "iva", "ivamo", "ivate", "ivano")); + it_conj_passMood(namedArgs, "prem", false, root, Arrays.asList("ii", "isti", "ì", "immo", "iste", "irono")); + // Regular past historic synonyms: + passThroughOrFillIn(namedArgs, "prem3s2", root + "é", true); + passThroughOrFillIn(namedArgs, "prem3p2", root + "erono", true); + it_conj_passMood(namedArgs, "fut", true, root, Arrays.asList("irò", "irai", "irà", "iremo", "irete", "iranno")); + it_conj_passMood(namedArgs, "cond", true, root, Arrays.asList("irei", "iresti", "irebbe", "iremmo", "ireste", "irebbero")); + + if (!name.endsWith("-b")) { + passThroughOrFillIn(namedArgs, "sub123s", root + i + "a", false); + passThroughOrFillIn(namedArgs, "sub3p", root + i + "ano", false); + } else { + passThroughOrFillIn(namedArgs, "sub123s", root + "isca", false); + passThroughOrFillIn(namedArgs, "sub3p", root + "iscano", false); + } + passThroughOrFillIn(namedArgs, "sub1p", root + "iamo", false); + passThroughOrFillIn(namedArgs, "sub2p", root + "iate", false); + + passThroughOrFillIn(namedArgs, "impsub12s", root + "issi", false); + passThroughOrFillIn(namedArgs, "impsub3s", root + "isse", false); + passThroughOrFillIn(namedArgs, "impsub1p", root + "issimo", false); + passThroughOrFillIn(namedArgs, "impsub2p", root + "iste", false); + passThroughOrFillIn(namedArgs, "impsub3p", root + "issero", false); + + if (!name.endsWith("-b")) { + passThroughOrFillIn(namedArgs, "imp2s", root + "i" + (si ? "ti" : ""), true); + passThroughOrFillIn(namedArgs, "imp3s", (si ? "si " : "") + root + i + "a", true); + passThroughOrFillIn(namedArgs, "imp3p", (si ? "si " : "") + root + i + "ano", true); + } else { + passThroughOrFillIn(namedArgs, "imp2s", root + "isci" + (si ? "ti" : ""), true); + passThroughOrFillIn(namedArgs, "imp3s", (si ? "si " : "") + root + "isca", true); + passThroughOrFillIn(namedArgs, "imp3p", (si ? "si " : "") + root + "iscano", true); + } + passThroughOrFillIn(namedArgs, "imp1p", root + "iamo" + (si ? "ci" : ""), true); + passThroughOrFillIn(namedArgs, "imp2p", root + "ite" + (si ? "vi" : ""), true); + + return dest.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, appendAndIndexWikiCallback); + } + } + + + static final class it_conj_ere implements FunctionCallback { + final it_conj dest; + it_conj_ere(it_conj dest) { + this.dest = dest; + } + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final String root = args.get(0); + final boolean si = name.equals("it-conj-ersi"); + + passThroughOrFillIn(namedArgs, "inf", root + (si ? "ersi" : "ere"), false); + namedArgs.put("aux", ListUtil.get(args, 1, "")); + passThroughOrFillIn(namedArgs, "ger", root + "endo" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "presp", root + "ente" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "pastp", root + "uto", true); + if (si) { + passThroughOrFillIn(namedArgs, "pastp2", root + "utosi", true); + } + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList("o", "i", "e", "iamo", "ete", "ono")); + it_conj_passMood(namedArgs, "imperf", false, root, Arrays.asList("evo", "evi", "eva", "evamo", "evate", "evano")); + it_conj_passMood(namedArgs, "prem", false, root, Arrays.asList("ei", "esti", "ette", "emmo", "este", "ettero")); + // Regular past historic synonyms: + passThroughOrFillIn(namedArgs, "prem3s2", root + "é", true); + passThroughOrFillIn(namedArgs, "prem3p2", root + "erono", true); + it_conj_passMood(namedArgs, "fut", true, root, Arrays.asList("erò", "erai", "erà", "eremo", "erete", "eranno")); + it_conj_passMood(namedArgs, "cond", true, root, Arrays.asList("erei", "eresti", "erebbe", "eremmo", "ereste", "erebbero")); + + passThroughOrFillIn(namedArgs, "sub123s", root + "a", false); + passThroughOrFillIn(namedArgs, "sub1p", root + "iamo", false); + passThroughOrFillIn(namedArgs, "sub2p", root + "iate", false); + passThroughOrFillIn(namedArgs, "sub3p", root + "ano", false); + + passThroughOrFillIn(namedArgs, "impsub12s", root + "essi", false); + passThroughOrFillIn(namedArgs, "impsub3s", root + "esse", false); + passThroughOrFillIn(namedArgs, "impsub1p", root + "essimo", false); + passThroughOrFillIn(namedArgs, "impsub2p", root + "este", false); + passThroughOrFillIn(namedArgs, "impsub3p", root + "essero", false); + + passThroughOrFillIn(namedArgs, "imp2s", root + "i" + (si ? "ti" : ""), true); + passThroughOrFillIn(namedArgs, "imp3s", (si ? "si " : "") + root + "a", true); + passThroughOrFillIn(namedArgs, "imp1p", root + "iamo" + (si ? "ci" : ""), true); + passThroughOrFillIn(namedArgs, "imp2p", root + "ete" + (si ? "vi" : ""), true); + passThroughOrFillIn(namedArgs, "imp3p", (si ? "si " : "") + root + "ano", true); + + return dest.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, appendAndIndexWikiCallback); + } + } + + static final class it_conj_urre implements FunctionCallback { + final it_conj dest; + it_conj_urre(it_conj dest) { + this.dest = dest; + } + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final String root = args.get(0); + final boolean si = name.equals("it-conj-ursi"); + + passThroughOrFillIn(namedArgs, "inf", root + (si ? "ursi" : "urre"), false); + namedArgs.put("aux", ListUtil.get(args, 1, "")); + passThroughOrFillIn(namedArgs, "ger", root + "ucendo" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "presp", root + "ucente" + (si ? "si" : ""), true); + passThroughOrFillIn(namedArgs, "pastp", root + "otto", true); + if (si) { + passThroughOrFillIn(namedArgs, "pastp2", root + "ottosi", true); + } + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList("uco", "uci", "uce", "uciamo", "ucete", "ucono")); + it_conj_passMood(namedArgs, "imperf", false, root, Arrays.asList("ucevo", "ucevi", "uceva", "ucevamo", "ucevate", "ucevano")); + it_conj_passMood(namedArgs, "prem", false, root, Arrays.asList("ussi", "ucesti", "usse", "ucemmo", "uceste", "ussero")); + it_conj_passMood(namedArgs, "fut", true, root, Arrays.asList("urrò", "urrai", "urrà", "urremo", "urrete", "urranno")); + it_conj_passMood(namedArgs, "cond", true, root, Arrays.asList("urrei", "urresti", "urrebbe", "urremmo", "urreste", "urrebbero")); + + passThroughOrFillIn(namedArgs, "sub123s", root + "uca", false); + passThroughOrFillIn(namedArgs, "sub1p", root + "uciamo", false); + passThroughOrFillIn(namedArgs, "sub2p", root + "uciate", false); + passThroughOrFillIn(namedArgs, "sub3p", root + "ucano", false); + + passThroughOrFillIn(namedArgs, "impsub12s", root + "ucessi", false); + passThroughOrFillIn(namedArgs, "impsub3s", root + "ucesse", false); + passThroughOrFillIn(namedArgs, "impsub1p", root + "ucessimo", false); + passThroughOrFillIn(namedArgs, "impsub2p", root + "uceste", false); + passThroughOrFillIn(namedArgs, "impsub3p", root + "ucessero", false); + + passThroughOrFillIn(namedArgs, "imp2s", root + "uci" + (si ? "ti" : ""), true); + passThroughOrFillIn(namedArgs, "imp3s", (si ? "si" : "") + root + "uca", true); + passThroughOrFillIn(namedArgs, "imp1p", root + "uciamo" + (si ? "ci" : ""), true); + passThroughOrFillIn(namedArgs, "imp2p", root + "ucete" + (si ? "vi" : ""), true); + passThroughOrFillIn(namedArgs, "imp3p", (si ? "si" : "") + root + "ucano", true); + + return dest.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, appendAndIndexWikiCallback); + } + } + + static final class it_conj_fare implements FunctionCallback { + final it_conj dest; + it_conj_fare(it_conj dest) { + this.dest = dest; + } + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + final String root = args.get(0); + passThroughOrFillIn(namedArgs, "inf", root + "fare", false); + namedArgs.put("aux", ListUtil.get(args, 1, "")); + passThroughOrFillIn(namedArgs, "ger", root + "facendo", true); + passThroughOrFillIn(namedArgs, "presp", root + "facente", true); + passThroughOrFillIn(namedArgs, "pastp", root + "fatto", true); + it_conj_passMood(namedArgs, "pres", false, root, Arrays.asList("faccio", "fai", "fà", "facciamo", "fate", "fanno")); + passThroughOrFillIn(namedArgs, "pres1s2", root + "fò", true); + it_conj_passMood(namedArgs, "imperf", false, root, Arrays.asList("facevo", "facevi", "faceva", "facevamo", "facevate", "facevano")); + it_conj_passMood(namedArgs, "prem", false, root, Arrays.asList("feci", "facesti", "fece", "facemmo", "faceste", "fecero")); + it_conj_passMood(namedArgs, "fut", true, root, Arrays.asList("farò", "farai", "farà", "faremo", "farete", "faranno")); + it_conj_passMood(namedArgs, "cond", true, root, Arrays.asList("farei", "faresti", "farebbe", "faremmo", "fareste", "farebbero")); + + passThroughOrFillIn(namedArgs, "sub123s", root + "faccia", false); + passThroughOrFillIn(namedArgs, "sub1p", root + "facciamo", false); + passThroughOrFillIn(namedArgs, "sub2p", root + "facciate", false); + passThroughOrFillIn(namedArgs, "sub3p", root + "facciano", false); + + passThroughOrFillIn(namedArgs, "impsub12s", root + "facessi", false); + passThroughOrFillIn(namedArgs, "impsub3s", root + "facesse", false); + passThroughOrFillIn(namedArgs, "impsub1p", root + "facessimo", false); + passThroughOrFillIn(namedArgs, "impsub2p", root + "faceste", false); + passThroughOrFillIn(namedArgs, "impsub3p", root + "facessero", false); + + passThroughOrFillIn(namedArgs, "imp2s", root + "fa", true); + passThroughOrFillIn(namedArgs, "imp3s", root + "faccia", true); + passThroughOrFillIn(namedArgs, "imp1p", root + "facciamo", true); + passThroughOrFillIn(namedArgs, "imp2p", root + "fate", true); + passThroughOrFillIn(namedArgs, "imp3p", root + "facciano", true); + + return dest.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, appendAndIndexWikiCallback); + } + } + + static final Map it_indicativePronouns = new LinkedHashMap(); + static { + it_indicativePronouns.put("1s", "io"); + it_indicativePronouns.put("2s", "tu"); + it_indicativePronouns.put("3s", "lui/lei"); + it_indicativePronouns.put("1p", "noi"); + it_indicativePronouns.put("2p", "voi"); + it_indicativePronouns.put("3p", "essi/esse"); + } + + static final Map it_subjunctivePronouns = new LinkedHashMap(); + static { + it_subjunctivePronouns.put("1s", "che io"); + it_subjunctivePronouns.put("2s", "che tu"); + it_subjunctivePronouns.put("3s", "che lui/lei"); + it_subjunctivePronouns.put("1p", "che noi"); + it_subjunctivePronouns.put("2p", "che voi"); + it_subjunctivePronouns.put("3p", "che essi/esse"); + } + + static final Map it_imperativePronouns = new LinkedHashMap(); + static { + it_imperativePronouns.put("1s", "-"); + it_imperativePronouns.put("2s", "tu"); + it_imperativePronouns.put("3s", "lui/lei"); + it_imperativePronouns.put("1p", "noi"); + it_imperativePronouns.put("2p", "voi"); + it_imperativePronouns.put("3p", "essi/esse"); + } + + + static final class it_conj implements FunctionCallback { + @Override + public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List args, + final Map namedArgs, + final T parser, + final AppendAndIndexWikiCallback appendAndIndexWikiCallback) { + + final StringBuilder builder = appendAndIndexWikiCallback.builder; + + final String inf = namedArgs.get("inf"); + + // TODO: center everything horizontally. + builder.append(""); + + builder.append(""); + builder.append(""); + builder.append(""); + builder.append("\n"); + + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append("\n"); + + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append("\n"); + + final List prefixes = (inf != null && inf.endsWith("si")) ? it_reflexive_pronouns : it_empty; + + String style = " style=\"background:#c0cfe4\""; + outputDataRow(appendAndIndexWikiCallback, style, "indicativo", style, "th", "", new LinkedHashMap(it_indicativePronouns), it_empty, false); + outputDataRow(appendAndIndexWikiCallback, style, "presente", "", "td", "pres", namedArgs, prefixes, true); + outputDataRow(appendAndIndexWikiCallback, style, "imperfetto", "", "td", "imperf", namedArgs, prefixes, true); + outputDataRow(appendAndIndexWikiCallback, style, "passato remoto", "", "td", "prem", namedArgs, prefixes, true); + outputDataRow(appendAndIndexWikiCallback, style, "futuro", "", "td", "fut", namedArgs, prefixes, true); + + style = " style=\"background:#c0d8e4\""; + outputDataRow(appendAndIndexWikiCallback, style, "condizionale", style, "th", "", new LinkedHashMap(it_indicativePronouns), it_empty, false); + outputDataRow(appendAndIndexWikiCallback, style, "presente", "", "td", "cond", namedArgs, prefixes, true); + + style = " style=\"background:#c0e4c0\""; + outputDataRow(appendAndIndexWikiCallback, style, "congiuntivo", style, "th", "", new LinkedHashMap(it_subjunctivePronouns), it_empty, false); + namedArgs.put("sub3s2", namedArgs.remove("sub3s")); + namedArgs.put("sub1s", namedArgs.get("sub123s")); + namedArgs.put("sub2s", namedArgs.get("sub123s")); + namedArgs.put("sub3s", namedArgs.remove("sub123s")); + namedArgs.put("sub1s2", namedArgs.get("sub123s2")); + namedArgs.put("sub2s2", namedArgs.get("sub123s2")); + namedArgs.put("sub3s2", namedArgs.remove("sub123s2")); + outputDataRow(appendAndIndexWikiCallback, style, "presente", "", "td", "sub", namedArgs, prefixes, true); + namedArgs.put("impsub1s", namedArgs.get("impsub12s")); + namedArgs.put("impsub2s", namedArgs.remove("impsub12s")); + namedArgs.put("impsub1s2", namedArgs.get("impsub12s2")); + namedArgs.put("impsub2s2", namedArgs.remove("impsub12s2")); + outputDataRow(appendAndIndexWikiCallback, style, "imperfetto", "", "td", "impsub", namedArgs, prefixes, true); + + style = " style=\"background:#e4d4c0\""; + outputDataRow(appendAndIndexWikiCallback, style, "imperativo", style, "th", "", new LinkedHashMap(it_imperativePronouns), it_empty, false); + outputDataRow(appendAndIndexWikiCallback, style, "", "", "td", "imp", namedArgs, it_empty, false); // these are attached to the stem. + + builder.append("
infinito"); + appendAndIndexWikiCallback.dispatch(MapUtil.safeRemove(namedArgs, "inf", "-"), null); + builder.append("
verbo ausiliare"); + appendAndIndexWikiCallback.dispatch(MapUtil.safeRemove(namedArgs, "aux", "-"), null); + builder.append("gerundio"); + outputKeyVariations(appendAndIndexWikiCallback, builder, "ger", namedArgs, true); + builder.append("
participio presente"); + outputKeyVariations(appendAndIndexWikiCallback, builder, "presp", namedArgs, true); + builder.append("participio passato"); + outputKeyVariations(appendAndIndexWikiCallback, builder, "pastp", namedArgs, true); + builder.append("
\n"); + + if (!namedArgs.isEmpty()) { + System.err.println("NON-EMPTY namedArgs: " + namedArgs); + if ("muovesse".equals(namedArgs.get("impsib3s2"))) { + return false; + } + if ("percuotesse".equals(namedArgs.get("impsib3s2"))) { + return false; + } + // Too many to deal with: + //assert false; + return false; + } + + return true; + } + + private void outputDataRow(AppendAndIndexWikiCallback appendAndIndexWikiCallback, + String col1Style, String headerName, + String col2Style, final String type2, + String moodName, Map namedArgs, final List prefixes, final boolean isForm) { + final StringBuilder builder = appendAndIndexWikiCallback.builder; + builder.append(""); + builder.append("").append(headerName).append(""); + int i = 0; + for (final String number : it_number_s_p) { + for (final String person : it_person_1_2_3) { + // Output or + builder.append("<").append(type2).append("").append(col2Style).append(">"); + final String keyBase = String.format("%s%s%s", moodName, person, number); + appendAndIndexWikiCallback.dispatch(prefixes.get(i++), null); + outputKeyVariations(appendAndIndexWikiCallback, builder, keyBase, namedArgs, isForm); + // Output or + builder.append(""); + } + } + builder.append("\n"); + } + } + + static void passThroughOrFillIn(final Map namedArgs, final String key, final String fillIn, final boolean quoteToEmpty) { + final String value = namedArgs.get(key); + if (quoteToEmpty && "''".equals(value)) { + namedArgs.put(key, ""); + return; + } + if (value == null || value.equals("")) { + namedArgs.put(key, fillIn); + } + } + + static final List it_number_s_p = Arrays.asList("s", "p"); + static final List it_person_1_2_3 = Arrays.asList("1", "2", "3"); + static final List it_reflexive_pronouns = Arrays.asList("mi ", "ti ", "si ", "ci ", "vi ", "si "); + static final List it_empty = Arrays.asList("", "", "", "", "", ""); + static void it_conj_passMood(final Map namedArgs, final String moodName, final boolean quoteToEmpty, final String root, final List suffixes) { + assert suffixes.size() == 6; + int i = 0; + for (final String number : it_number_s_p) { + for (final String person : it_person_1_2_3) { + passThroughOrFillIn(namedArgs, String.format("%s%s%s", moodName, person, number), root + suffixes.get(i), quoteToEmpty); + ++i; + } + } + } + + private static void outputKeyVariations(AppendAndIndexWikiCallback appendAndIndexWikiCallback, + final StringBuilder builder, final String keyBase, Map namedArgs, boolean isForm) { + for (int suffix = 0; suffix <= 4; ++suffix) { + final String key = suffix == 0 ? keyBase : keyBase + suffix; + final String val = namedArgs.remove(key); + if (val != null && !val.trim().equals("")) { + if (suffix > 0) { + builder.append(", "); + } + appendAndIndexWikiCallback.dispatch(val, null); + if (isForm) { + appendAndIndexWikiCallback.parser.addLinkToCurrentEntry(val, EntryTypeName.WIKTIONARY_INFLECTED_FORM_MULTI); + } + } + } + } + - } \ No newline at end of file +} \ No newline at end of file