1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 package com.hughes.android.dictionary.parser;
17 import java.io.BufferedInputStream;
18 import java.io.DataInputStream;
19 import java.io.EOFException;
21 import java.io.FileInputStream;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.LinkedHashSet;
28 import java.util.List;
31 import java.util.logging.Logger;
32 import java.util.regex.Pattern;
34 import com.hughes.android.dictionary.engine.EntryTypeName;
35 import com.hughes.android.dictionary.engine.IndexBuilder;
36 import com.hughes.android.dictionary.engine.IndexedEntry;
37 import com.hughes.android.dictionary.engine.PairEntry;
38 import com.hughes.android.dictionary.engine.PairEntry.Pair;
40 public class EnWiktionaryXmlParser {
42 static final Logger LOG = Logger.getLogger(EnWiktionaryXmlParser.class.getName());
44 // TODO: look for {{ and [[ and <adf> <!-- in output.
45 // TODO: process {{ttbc}} lines
47 static final Pattern partOfSpeechHeader = Pattern.compile(
48 "Noun|Verb|Adjective|Adverb|Pronoun|Conjunction|Interjection|" +
49 "Preposition|Proper noun|Article|Prepositional phrase|Acronym|" +
50 "Abbreviation|Initialism|Contraction|Prefix|Suffix|Symbol|Letter|" +
51 "Ligature|Idiom|Phrase|" +
52 // These are @deprecated:
53 "Noun form|Verb form|Adjective form|Nominal phrase|Noun phrase|" +
54 "Verb phrase|Transitive verb|Intransitive verb|Reflexive verb|" +
55 // These are extras I found:
56 "Determiner|Numeral|Number|Cardinal number|Ordinal number|Proverb|" +
57 "Particle|Interjection|Pronominal adverb" +
58 "Han character|Hanzi|Hanja|Kanji|Katakana character|Syllable");
60 final IndexBuilder enIndexBuilder;
61 final IndexBuilder otherIndexBuilder;
62 final Pattern langPattern;
63 final Pattern langCodePattern;
66 public EnWiktionaryXmlParser(final IndexBuilder enIndexBuilder, final IndexBuilder otherIndexBuilder, final Pattern langPattern, final Pattern langCodePattern, final boolean swap) {
67 this.enIndexBuilder = enIndexBuilder;
68 this.otherIndexBuilder = otherIndexBuilder;
69 this.langPattern = langPattern;
70 this.langCodePattern = langCodePattern;
75 public void parse(final File file, final int pageLimit) throws IOException {
77 final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
79 if (pageLimit >= 0 && pageCount >= pageLimit) {
85 title = dis.readUTF();
86 } catch (EOFException e) {
90 final String heading = dis.readUTF();
91 final int bytesLength = dis.readInt();
92 final byte[] bytes = new byte[bytesLength];
94 final String text = new String(bytes, "UTF8");
96 parseSection(title, heading, text);
99 if (pageCount % 1000 == 0) {
100 LOG.info("pageCount=" + pageCount);
105 private void parseSection(final String title, String heading, final String text) {
106 if (title.startsWith("Wiktionary:") ||
107 title.startsWith("Template:") ||
108 title.startsWith("Appendix:") ||
109 title.startsWith("Category:") ||
110 title.startsWith("Index:") ||
111 title.startsWith("MediaWiki:") ||
112 title.startsWith("TransWiki:") ||
113 title.startsWith("Citations:") ||
114 title.startsWith("Concordance:") ||
115 title.startsWith("Help:")) {
119 heading = heading.replaceAll("=", "").trim();
120 if (heading.equals("English")) {
121 doEnglishWord(title, text);
122 } else if (langPattern.matcher(heading).matches()){
123 doForeignWord(title, text);
128 // -------------------------------------------------------------------------
133 private void doEnglishWord(String title, String text) {
134 final WikiTokenizer wikiTokenizer = new WikiTokenizer(text);
135 while (wikiTokenizer.nextToken() != null) {
137 if (wikiTokenizer.isHeading()) {
138 final String headerName = wikiTokenizer.headingWikiText();
140 if (wikiTokenizer.headingDepth() <= posDepth) {
145 if (partOfSpeechHeader.matcher(headerName).matches()) {
146 posDepth = wikiTokenizer.headingDepth();
147 pos = wikiTokenizer.headingWikiText();
148 } else if (headerName.equals("Translations")) {
149 doTranslations(title, wikiTokenizer);
150 } else if (headerName.equals("Pronunciation")) {
151 //doPronunciation(wikiLineReader);
158 private static Set<String> encodings = new LinkedHashSet<String>(Arrays.asList("zh-ts",
159 "sd-Arab", "ku-Arab", "Arab", "unicode", "Laoo", "ur-Arab", "Thai",
160 "fa-Arab", "Khmr", "zh-tsp", "Cyrl", "IPAchar", "ug-Arab", "ko-inline",
161 "Jpan", "Kore", "Hebr", "rfscript", "Beng", "Mong", "Knda", "Cyrs",
162 "yue-tsj", "Mlym", "Tfng", "Grek", "yue-yue-j"));
164 private void doTranslations(final String title, final WikiTokenizer wikiTokenizer) {
165 if (title.equals("absolutely")) {
166 System.out.println();
170 boolean done = false;
171 while (wikiTokenizer.nextToken() != null) {
172 if (wikiTokenizer.isHeading()) {
173 wikiTokenizer.returnToLineStart();
180 // Check whether we care about this line:
182 //line = WikiLineReader.removeSquareBrackets(line);
184 if (wikiTokenizer.isFunction()) {
185 final String functionName = wikiTokenizer.functionName();
186 final List<String> positionArgs = wikiTokenizer.functionPositionArgs();
188 if (functionName.equals("trans-top")) {
190 if (wikiTokenizer.functionPositionArgs().size() >= 1) {
191 sense = positionArgs.get(0);
192 // TODO: could emphasize words in [[brackets]] inside sense.
193 sense = WikiTokenizer.toPlainText(sense);
194 //LOG.info("Sense: " + sense);
196 } else if (functionName.equals("trans-bottom")) {
198 } else if (functionName.equals("trans-mid")) {
199 } else if (functionName.equals("trans-see")) {
201 } else if (functionName.startsWith("picdic")) {
202 } else if (functionName.startsWith("checktrans")) {
203 } else if (functionName.startsWith("ttbc")) {
204 wikiTokenizer.nextLine();
205 // TODO: would be great to handle
206 //TODO: Check this: done = true;
208 LOG.warning("Unexpected translation wikifunction: " + wikiTokenizer.token() + ", title=" + title);
210 } else if (wikiTokenizer.isListItem() && wikiTokenizer.listItemPrefix().startsWith("*")) {
211 final String line = wikiTokenizer.listItemWikiText();
212 // This line could produce an output...
214 // First strip the language and check whether it matches.
215 // And hold onto it for sub-lines.
216 final int colonIndex = line.indexOf(":");
217 if (colonIndex == -1) {
221 final String lang = line.substring(0, colonIndex);
222 if (!this.langPattern.matcher(lang).find()) {
226 String rest = line.substring(colonIndex + 1).trim();
227 if (rest.length() > 0) {
228 doTranslationLine(line, title, sense, rest);
230 // TODO: do lines that are like Greek:
233 } else if (wikiTokenizer.remainderStartsWith("''See''")) {
234 wikiTokenizer.nextLine();
235 LOG.fine("Skipping line: " + wikiTokenizer.token());
236 } else if (wikiTokenizer.isWikiLink()) {
237 final String wikiLink = wikiTokenizer.wikiLinkText();
238 if (wikiLink.contains(":") && wikiLink.contains(title)) {
239 } else if (wikiLink.contains("Category:")) {
241 LOG.warning("Unexpected wikiLink: " + wikiTokenizer.token() + ", title=" + title);
243 } else if (wikiTokenizer.isNewline() || wikiTokenizer.isMarkup() || wikiTokenizer.isComment()) {
245 final String token = wikiTokenizer.token();
246 if (token.equals("----")) {
248 LOG.warning("Unexpected translation token: " + wikiTokenizer.token() + ", title=" + title);
255 private static <T> T get(final List<T> list, final int index) {
256 return index < list.size() ? list.get(index) : null;
259 private void doTranslationLine(final String line, final String title, final String sense, final String rest) {
260 // Good chance we'll actually file this one...
261 final PairEntry pairEntry = new PairEntry();
262 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
264 final StringBuilder otherText = new StringBuilder();
265 final WikiTokenizer wikiTokenizer = new WikiTokenizer(rest, false);
266 while (wikiTokenizer.nextToken() != null) {
268 if (wikiTokenizer.isPlainText()) {
269 final String plainText = wikiTokenizer.token();
270 otherText.append("").append(plainText);
271 otherIndexBuilder.addEntryWithString(indexedEntry, plainText, EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
273 } else if (wikiTokenizer.isWikiLink()) {
274 final String plainText = wikiTokenizer.wikiLinkText();
275 otherText.append("").append(plainText);
276 otherIndexBuilder.addEntryWithString(indexedEntry, plainText, EntryTypeName.WIKTIONARY_TRANSLATION_WIKI_TEXT);
278 } else if (wikiTokenizer.isFunction()) {
279 final String functionName = wikiTokenizer.functionName();
280 final List<String> args = wikiTokenizer.functionPositionArgs();
281 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
283 if (functionName.equals("t") || functionName.equals("t+") || functionName.equals("t-") || functionName.equals("tø") || functionName.equals("apdx-t")) {
284 if (args.size() < 2) {
285 LOG.warning("{{t}} with too few args: " + line + ", title=" + title);
288 final String langCode = get(args, 0);
289 //if (this.langCodePattern.matcher(langCode).matches()) {
290 final String word = get(args, 1);
291 final String gender = get(args, 2);
292 final String transliteration = namedArgs.get("tr");
293 if (otherText.length() > 0) {
294 otherText.append("");
296 otherText.append(word);
297 otherIndexBuilder.addEntryWithString(indexedEntry, word, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
298 if (gender != null) {
299 otherText.append(String.format(" {%s}", gender));
301 if (transliteration != null) {
302 otherText.append(String.format(" (tr. %s)", transliteration));
303 otherIndexBuilder.addEntryWithString(indexedEntry, transliteration, EntryTypeName.WIKTIONARY_TRANSLITERATION);
306 } else if (functionName.equals("qualifier")) {
307 String qualifier = args.get(0);
308 if (!namedArgs.isEmpty() || args.size() > 1) {
309 LOG.warning("weird qualifier: " + line);
312 otherText.append("(").append(qualifier).append(")");
313 } else if (encodings.contains(functionName)) {
314 otherText.append("").append(args.get(0));
315 otherIndexBuilder.addEntryWithString(indexedEntry, args.get(0), EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
316 } else if (isGender(functionName)) {
317 appendGender(otherText, functionName, args);
318 } else if (functionName.equals("g")) {
319 otherText.append("{g}");
320 } else if (functionName.equals("l")) {
321 // encodes text in various langs.
323 otherText.append("").append(args.get(1));
324 otherIndexBuilder.addEntryWithString(indexedEntry, args.get(1), EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
325 // TODO: transliteration
326 } else if (functionName.equals("term")) {
327 // cross-reference to another dictionary
328 otherText.append("").append(args.get(0));
329 otherIndexBuilder.addEntryWithString(indexedEntry, args.get(0), EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
330 // TODO: transliteration
331 } else if (functionName.equals("italbrac") || functionName.equals("gloss")) {
332 // TODO: put this text aside to use it.
333 otherText.append("[").append(args.get(0)).append("]");
334 otherIndexBuilder.addEntryWithString(indexedEntry, args.get(0), EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
335 } else if (functionName.equals("ttbc")) {
336 LOG.warning("Unexpected {{ttbc}}");
337 } else if (functionName.equals("trreq")) {
338 } else if (functionName.equals("not used")) {
339 otherText.append("(not used)");
340 } else if (functionName.equals("t-image")) {
341 // American sign language
344 otherText.append(wikiTokenizer.token());
347 } else if (wikiTokenizer.isNewline()) {
349 } else if (wikiTokenizer.isComment()) {
350 } else if (wikiTokenizer.isMarkup()) {
352 LOG.warning("Bad translation token: " + wikiTokenizer.token());
355 if (otherText.length() == 0) {
356 LOG.warning("Empty otherText: " + line);
360 StringBuilder englishText = new StringBuilder();
362 englishText.append(title);
364 englishText.append(" (").append(sense).append(")");
365 enIndexBuilder.addEntryWithString(indexedEntry, sense, EntryTypeName.WIKTIONARY_TRANSLATION_SENSE, EntryTypeName.WIKTIONARY_TRANSLATION_SENSE);
368 englishText.append(" (").append(pos.toLowerCase()).append(")");
370 enIndexBuilder.addEntryWithString(indexedEntry, title, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
372 final Pair pair = new Pair(trim(englishText.toString()), trim(otherText.toString()), swap);
373 pairEntry.pairs.add(pair);
374 if (!pairsAdded.add(pair.toString())) {
375 LOG.warning("Duplicate pair: " + pair.toString());
377 if (pair.toString().equals("libero {m} :: free (adjective)")) {
378 System.out.println();
384 private void appendGender(final StringBuilder otherText,
385 final String functionName, final List<String> args) {
386 otherText.append("{");
387 otherText.append(functionName);
388 for (int i = 0; i < args.size(); ++i) {
389 otherText.append("|").append(args.get(i));
391 otherText.append("}");
395 private boolean isGender(final String functionName) {
396 return functionName.equals("m") || functionName.equals("f") || functionName.equals("n") || functionName.equals("p");
399 Set<String> pairsAdded = new LinkedHashSet<String>();
401 // -------------------------------------------------------------------------
403 private void doForeignWord(final String title, final String text) {
404 final WikiTokenizer wikiTokenizer = new WikiTokenizer(text);
405 while (wikiTokenizer.nextToken() != null) {
406 if (wikiTokenizer.isHeading()) {
407 final String headingName = wikiTokenizer.headingWikiText();
408 if (headingName.equals("Translations")) {
409 LOG.warning("Translations not in English section: " + title);
410 } else if (headingName.equals("Pronunciation")) {
411 //doPronunciation(wikiLineReader);
412 } else if (partOfSpeechHeader.matcher(headingName).matches()) {
413 doForeignPartOfSpeech(title, headingName, wikiTokenizer.headingDepth(), wikiTokenizer);
420 static final class ListSection {
421 final String firstPrefix;
422 final String firstLine;
423 final List<String> nextPrefixes = new ArrayList<String>();
424 final List<String> nextLines = new ArrayList<String>();
426 public ListSection(String firstPrefix, String firstLine) {
427 this.firstPrefix = firstPrefix;
428 this.firstLine = firstLine;
432 public String toString() {
433 return firstPrefix + firstLine + "{ " + nextPrefixes + "}";
438 int foreignCount = 0;
439 private void doForeignPartOfSpeech(String title, final String posHeading, final int posDepth, WikiTokenizer wikiTokenizer) {
440 if (++foreignCount % 1000 == 0) {
441 LOG.info("***" + title + ", pos=" + posHeading + ", foreignCount=" + foreignCount);
443 if (title.equals("moro")) {
444 System.out.println();
447 final StringBuilder foreignBuilder = new StringBuilder();
448 final Collection<String> wordForms = new ArrayList<String>();
449 final List<ListSection> listSections = new ArrayList<ListSection>();
453 ListSection lastListSection = null;
455 int currentHeadingDepth = posDepth;
456 while (wikiTokenizer.nextToken() != null) {
457 if (wikiTokenizer.isHeading()) {
458 currentHeadingDepth = wikiTokenizer.headingDepth();
460 if (currentHeadingDepth <= posDepth) {
461 wikiTokenizer.returnToLineStart();
466 if (currentHeadingDepth > posDepth) {
471 if (wikiTokenizer.isFunction()) {
472 final String name = wikiTokenizer.functionName();
473 final List<String> args = wikiTokenizer.functionPositionArgs();
474 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
475 // First line is generally a repeat of the title with some extra information.
476 // We need to build up the left side (foreign text, tokens) separately from the
477 // right side (English). The left-side may get paired with multiple right sides.
478 // The left side should get filed under every form of the word in question (singular, plural).
480 // For verbs, the conjugation comes later on in a deeper section.
481 // Ideally, we'd want to file every English entry with the verb
482 // under every verb form coming from the conjugation.
483 // Ie. under "fa": see: "make :: fare" and "do :: fare"
484 // But then where should we put the conjugation table?
485 // I think just under fare. But then we need a way to link to the entry (actually the row, since entries doesn't show up!)
486 // for the conjugation table from "fa".
487 // Would like to be able to link to a lang#token.
488 if (isGender(name)) {
489 appendGender(foreignBuilder, name, args);
490 } else if (name.equals("wikipedia")) {
491 namedArgs.remove("lang");
492 if (args.size() > 1 || !namedArgs.isEmpty()) {
494 foreignBuilder.append(wikiTokenizer.token());
495 } else if (args.size() == 1) {
496 foreignBuilder.append(wikiTokenizer.token());
498 //foreignBuilder.append(title);
500 } else if (name.equals("it-noun")) {
501 final String base = get(args, 0);
502 final String gender = get(args, 1);
503 final String singular = base + get(args, 2);
504 final String plural = base + get(args, 3);
505 foreignBuilder.append(String.format(" %s {%s}, %s {pl}", singular, gender, plural, plural));
506 wordForms.add(singular);
507 wordForms.add(plural);
508 } else if (name.equals("it-proper noun")) {
509 foreignBuilder.append(wikiTokenizer.token());
510 } else if (name.equals("it-adj")) {
511 foreignBuilder.append(wikiTokenizer.token());
512 } else if (name.startsWith("it-conj")) {
513 if (name.equals("it-conj-are")) {
514 itConjAre(args, namedArgs);
515 } else if (name.equals("it-conj-ere")) {
516 } else if (name.equals("it-conj-ire")) {
518 LOG.warning("Unknown conjugation: " + wikiTokenizer.token());
522 foreignBuilder.append(wikiTokenizer.token());
523 // LOG.warning("Unknown function: " + wikiTokenizer.token());
526 } else if (wikiTokenizer.isListItem()) {
527 final String prefix = wikiTokenizer.listItemPrefix();
528 if (lastListSection != null &&
529 prefix.startsWith(lastListSection.firstPrefix) &&
530 prefix.length() > lastListSection.firstPrefix.length()) {
531 lastListSection.nextPrefixes.add(prefix);
532 lastListSection.nextLines.add(wikiTokenizer.listItemWikiText());
534 lastListSection = new ListSection(prefix, wikiTokenizer.listItemWikiText());
535 listSections.add(lastListSection);
537 } else if (lastListSection != null) {
538 // Don't append anything after the lists, because there's crap.
539 } else if (wikiTokenizer.isWikiLink()) {
541 foreignBuilder.append(wikiTokenizer.wikiLinkText());
543 } else if (wikiTokenizer.isPlainText()) {
545 foreignBuilder.append(wikiTokenizer.token());
547 } else if (wikiTokenizer.isMarkup() || wikiTokenizer.isNewline() || wikiTokenizer.isComment()) {
550 LOG.warning("Unexpected token: " + wikiTokenizer.token());
555 // Here's where we exit.
556 // TODO: Should we make an entry even if there are no foreign list items?
557 if (foreignBuilder.indexOf(title) == -1) {
558 foreignBuilder.insert(0, title + " ");
560 for (final ListSection listSection : listSections) {
561 doForeignListItem(foreignBuilder.toString(), title, wordForms, listSection);
567 static final Pattern UNINDEXED_WIKI_TEXT = Pattern.compile(
568 "(first|second|third)-person (singular|plural)|" +
574 private void doForeignListItem(final String foreignText, String title, final Collection<String> forms, final ListSection listSection) {
576 final String prefix = listSection.firstPrefix;
577 if (prefix.length() > 1) {
578 LOG.warning("Prefix too long: " + listSection);
582 final PairEntry pairEntry = new PairEntry();
583 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
585 final StringBuilder englishBuilder = new StringBuilder();
587 final String mainLine = listSection.firstLine;
589 final WikiTokenizer englishTokenizer = new WikiTokenizer(mainLine, false);
590 while (englishTokenizer.nextToken() != null) {
591 // TODO handle form of....
592 if (englishTokenizer.isPlainText()) {
593 englishBuilder.append(englishTokenizer.token());
594 enIndexBuilder.addEntryWithString(indexedEntry, englishTokenizer.token(), EntryTypeName.WIKTIONARY_ENGLISH_DEF);
595 } else if (englishTokenizer.isWikiLink()) {
596 final String text = englishTokenizer.wikiLinkText();
597 final String link = englishTokenizer.wikiLinkDest();
599 if (link.contains("#English")) {
600 englishBuilder.append(text);
601 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
602 } else if (link.contains("#") && this.langPattern.matcher(link).find()) {
603 englishBuilder.append(text);
604 otherIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_OTHER_LANG);
605 } else if (link.equals("plural")) {
606 englishBuilder.append(englishTokenizer.wikiLinkText());
608 //LOG.warning("Special link: " + englishTokenizer.token());
609 englishBuilder.append(englishTokenizer.wikiLinkText());
613 englishBuilder.append(text);
614 if (!UNINDEXED_WIKI_TEXT.matcher(text).find()) {
615 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
618 } else if (englishTokenizer.isFunction()) {
619 final String name = englishTokenizer.functionName();
620 if (name.contains("conjugation of ") ||
621 name.contains("form of ") ||
622 name.contains("feminine of ") ||
623 name.contains("plural of ")) {
624 // Ignore these in the index, they're really annoying....
625 englishBuilder.append(englishTokenizer.token());
627 englishBuilder.append(englishTokenizer.token());
628 // LOG.warning("Unexpected function: " + englishTokenizer.token());
631 if (englishTokenizer.isComment() || englishTokenizer.isMarkup()) {
633 LOG.warning("Unexpected definition text: " + englishTokenizer.token());
637 final String english = trim(englishBuilder.toString());
638 if (english.length() > 0) {
639 final Pair pair = new Pair(english, trim(foreignText), this.swap);
640 pairEntry.pairs.add(pair);
641 otherIndexBuilder.addEntryWithString(indexedEntry, title, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
642 for (final String form : forms) {
643 otherIndexBuilder.addEntryWithString(indexedEntry, form, EntryTypeName.WIKTIONARY_FORM_SINGLE, EntryTypeName.WIKTIONARY_FORM_MULTI);
649 private void itConjAre(List<String> args, Map<String, String> namedArgs) {
650 final String base = args.get(0);
651 final String aux = args.get(1);
653 putIfMissing(namedArgs, "inf", base + "are");
654 putIfMissing(namedArgs, "aux", aux);
655 putIfMissing(namedArgs, "ger", base + "ando");
656 putIfMissing(namedArgs, "presp", base + "ante");
657 putIfMissing(namedArgs, "pastp", base + "ato");
659 putIfMissing(namedArgs, "pres1s", base + "o");
660 putIfMissing(namedArgs, "pres2s", base + "i");
661 putIfMissing(namedArgs, "pres3s", base + "a");
662 putIfMissing(namedArgs, "pres1p", base + "iamo");
663 putIfMissing(namedArgs, "pres2p", base + "ate");
664 putIfMissing(namedArgs, "pres3p", base + "ano");
666 putIfMissing(namedArgs, "imperf1s", base + "avo");
667 putIfMissing(namedArgs, "imperf2s", base + "avi");
668 putIfMissing(namedArgs, "imperf3s", base + "ava");
669 putIfMissing(namedArgs, "imperf1p", base + "avamo");
670 putIfMissing(namedArgs, "imperf2p", base + "avate");
671 putIfMissing(namedArgs, "imperf3p", base + "avano");
673 putIfMissing(namedArgs, "prem1s", base + "ai");
674 putIfMissing(namedArgs, "prem2s", base + "asti");
675 putIfMissing(namedArgs, "prem3s", base + "ò");
676 putIfMissing(namedArgs, "prem1p", base + "ammo");
677 putIfMissing(namedArgs, "prem2p", base + "aste");
678 putIfMissing(namedArgs, "prem3p", base + "arono");
680 putIfMissing(namedArgs, "fut1s", base + "erò");
681 putIfMissing(namedArgs, "fut2s", base + "erai");
682 putIfMissing(namedArgs, "fut3s", base + "erà");
683 putIfMissing(namedArgs, "fut1p", base + "eremo");
684 putIfMissing(namedArgs, "fut2p", base + "erete");
685 putIfMissing(namedArgs, "fut3p", base + "eranno");
687 putIfMissing(namedArgs, "cond1s", base + "erei");
688 putIfMissing(namedArgs, "cond2s", base + "eresti");
689 putIfMissing(namedArgs, "cond3s", base + "erebbe");
690 putIfMissing(namedArgs, "cond1p", base + "eremmo");
691 putIfMissing(namedArgs, "cond2p", base + "ereste");
692 putIfMissing(namedArgs, "cond3p", base + "erebbero");
693 // Subjunctive / congiuntivo
694 putIfMissing(namedArgs, "sub123s", base + "i");
695 putIfMissing(namedArgs, "sub1p", base + "iamo");
696 putIfMissing(namedArgs, "sub2p", base + "iate");
697 putIfMissing(namedArgs, "sub3p", base + "ino");
698 // Imperfect subjunctive
699 putIfMissing(namedArgs, "impsub12s", base + "assi");
700 putIfMissing(namedArgs, "impsub3s", base + "asse");
701 putIfMissing(namedArgs, "impsub1p", base + "assimo");
702 putIfMissing(namedArgs, "impsub2p", base + "aste");
703 putIfMissing(namedArgs, "impsub3p", base + "assero");
705 putIfMissing(namedArgs, "imp2s", base + "a");
706 putIfMissing(namedArgs, "imp3s", base + "i");
707 putIfMissing(namedArgs, "imp1p", base + "iamo");
708 putIfMissing(namedArgs, "imp2p", base + "ate");
709 putIfMissing(namedArgs, "imp3p", base + "ino");
712 itConj(args, namedArgs);
716 private void itConj(List<String> args, Map<String, String> namedArgs) {
717 // TODO Auto-generated method stub
722 private static void putIfMissing(final Map<String, String> namedArgs, final String key,
723 final String value) {
724 final String oldValue = namedArgs.get(key);
725 if (oldValue == null || oldValue.length() == 0) {
726 namedArgs.put(key, value);
730 // TODO: check how ='' and =| are manifested....
731 // TODO: get this right in -are
732 private static void putOrNullify(final Map<String, String> namedArgs, final String key,
733 final String value) {
734 final String oldValue = namedArgs.get(key);
735 if (oldValue == null/* || oldValue.length() == 0*/) {
736 namedArgs.put(key, value);
738 if (oldValue.equals("''")) {
739 namedArgs.put(key, "");
744 static final Pattern whitespace = Pattern.compile("\\s+");
745 static String trim(final String s) {
746 return whitespace.matcher(s).replaceAll(" ").trim();