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 private void doForeignPartOfSpeech(String title, final String posHeading, final int posDepth, WikiTokenizer wikiTokenizer) {
439 LOG.info("***" + title + ", pos=" + posHeading);
440 if (title.equals("moro")) {
441 System.out.println();
444 final StringBuilder foreignBuilder = new StringBuilder();
445 Collection<String> wordForms = Collections.emptyList();
446 final List<ListSection> listSections = new ArrayList<ListSection>();
450 ListSection lastListSection = null;
452 int currentHeadingDepth = posDepth;
453 while (wikiTokenizer.nextToken() != null) {
454 if (wikiTokenizer.isHeading()) {
455 currentHeadingDepth = wikiTokenizer.headingDepth();
457 if (currentHeadingDepth <= posDepth) {
458 wikiTokenizer.returnToLineStart();
463 if (currentHeadingDepth > posDepth) {
468 if (wikiTokenizer.isFunction()) {
469 final String name = wikiTokenizer.functionName();
470 final List<String> args = wikiTokenizer.functionPositionArgs();
471 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
472 // First line is generally a repeat of the title with some extra information.
473 // We need to build up the left side (foreign text, tokens) separately from the
474 // right side (English). The left-side may get paired with multiple right sides.
475 // The left side should get filed under every form of the word in question (singular, plural).
477 // For verbs, the conjugation comes later on in a deeper section.
478 // Ideally, we'd want to file every English entry with the verb
479 // under every verb form coming from the conjugation.
480 // Ie. under "fa": see: "make :: fare" and "do :: fare"
481 // But then where should we put the conjugation table?
482 // 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!)
483 // for the conjugation table from "fa".
484 // Would like to be able to link to a lang#token.
485 if (isGender(name)) {
486 appendGender(foreignBuilder, name, args);
487 } else if (name.equals("wikipedia")) {
488 namedArgs.remove("lang");
489 if (args.size() > 1 || !namedArgs.isEmpty()) {
491 foreignBuilder.append(wikiTokenizer.token());
492 } else if (args.size() == 1) {
493 foreignBuilder.append(wikiTokenizer.token());
495 //foreignBuilder.append(title);
497 } else if (name.equals("it-noun")) {
498 assert wordForms.isEmpty();
499 final String base = get(args, 0);
500 final String gender = get(args, 1);
501 final String singular = base + get(args, 2);
502 final String plural = base + get(args, 3);
503 foreignBuilder.append(String.format("%s {%s}, %s {pl}", singular, gender, plural, plural));
504 wordForms = Arrays.asList(singular, plural);
505 } else if (name.equals("it-proper noun")) {
506 foreignBuilder.append(wikiTokenizer.token());
507 } else if (name.equals("it-adj")) {
508 foreignBuilder.append(wikiTokenizer.token());
509 } else if (name.startsWith("it-conj")) {
510 if (name.equals("it-conj-are")) {
511 itConjAre(args, namedArgs);
512 } else if (name.equals("it-conj-ere")) {
513 } else if (name.equals("it-conj-ire")) {
515 LOG.warning("Unknown conjugation: " + wikiTokenizer.token());
519 foreignBuilder.append(wikiTokenizer.token());
520 // LOG.warning("Unknown function: " + wikiTokenizer.token());
523 } else if (wikiTokenizer.isListItem()) {
524 final String prefix = wikiTokenizer.listItemPrefix();
525 if (lastListSection != null &&
526 prefix.startsWith(lastListSection.firstPrefix) &&
527 prefix.length() > lastListSection.firstPrefix.length()) {
528 lastListSection.nextPrefixes.add(prefix);
529 lastListSection.nextLines.add(wikiTokenizer.listItemWikiText());
531 lastListSection = new ListSection(prefix, wikiTokenizer.listItemWikiText());
532 listSections.add(lastListSection);
534 } else if (lastListSection != null) {
535 // Don't append anything after the lists, because there's crap.
536 } else if (wikiTokenizer.isWikiLink()) {
538 foreignBuilder.append(wikiTokenizer.wikiLinkText());
540 } else if (wikiTokenizer.isPlainText()) {
542 foreignBuilder.append(wikiTokenizer.token());
544 } else if (wikiTokenizer.isMarkup() || wikiTokenizer.isNewline() || wikiTokenizer.isComment()) {
547 LOG.warning("Unexpected token: " + wikiTokenizer.token());
552 // Here's where we exit.
553 // TODO: Should we make an entry even if there are no foreign list items?
554 if (foreignBuilder.indexOf(title) == -1) {
555 foreignBuilder.insert(0, title + " ");
557 for (final ListSection listSection : listSections) {
558 doForeignListItem(foreignBuilder.toString(), title, wordForms, listSection);
564 static final Pattern UNINDEXED_WIKI_TEXT = Pattern.compile(
565 "(first|second|third)-person (singular|plural)|" +
571 private void doForeignListItem(final String foreignText, String title, final Collection<String> forms, final ListSection listSection) {
573 final String prefix = listSection.firstPrefix;
574 if (prefix.length() > 1) {
575 LOG.warning("Prefix too long: " + listSection);
579 final PairEntry pairEntry = new PairEntry();
580 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
582 final StringBuilder englishBuilder = new StringBuilder();
584 final String mainLine = listSection.firstLine;
586 final WikiTokenizer englishTokenizer = new WikiTokenizer(mainLine, false);
587 while (englishTokenizer.nextToken() != null) {
588 // TODO handle form of....
589 if (englishTokenizer.isPlainText()) {
590 englishBuilder.append(englishTokenizer.token());
591 enIndexBuilder.addEntryWithString(indexedEntry, englishTokenizer.token(), EntryTypeName.WIKTIONARY_ENGLISH_DEF);
592 } else if (englishTokenizer.isWikiLink()) {
593 final String text = englishTokenizer.wikiLinkText();
594 final String link = englishTokenizer.wikiLinkDest();
596 if (link.contains("#English")) {
597 englishBuilder.append(text);
598 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
599 } else if (link.contains("#") && this.langPattern.matcher(link).find()) {
600 englishBuilder.append(text);
601 otherIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_OTHER_LANG);
603 LOG.warning("Special link: " + englishTokenizer.token());
604 // TODO: something here...
608 englishBuilder.append(text);
609 if (!UNINDEXED_WIKI_TEXT.matcher(text).find()) {
610 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
613 } else if (englishTokenizer.isFunction()) {
614 final String name = englishTokenizer.functionName();
615 if (name.contains(" conjugation of ") ||
616 name.contains(" form of ") ||
617 name.contains(" feminine of ") ||
618 name.contains(" plural of ")) {
619 // Ignore these in the index, they're really annoying....
620 englishBuilder.append(englishTokenizer.token());
622 LOG.warning("Unexpected function: " + englishTokenizer.token());
625 if (englishTokenizer.isComment() || englishTokenizer.isMarkup()) {
627 LOG.warning("Unexpected definition text: " + englishTokenizer.token());
631 final String english = trim(englishBuilder.toString());
632 if (english.length() > 0) {
633 final Pair pair = new Pair(english, trim(foreignText), this.swap);
634 pairEntry.pairs.add(pair);
635 otherIndexBuilder.addEntryWithString(indexedEntry, title, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
636 for (final String form : forms) {
637 otherIndexBuilder.addEntryWithString(indexedEntry, form, EntryTypeName.WIKTIONARY_FORM_SINGLE, EntryTypeName.WIKTIONARY_FORM_MULTI);
643 private void itConjAre(List<String> args, Map<String, String> namedArgs) {
644 final String base = args.get(0);
645 final String aux = args.get(1);
647 putIfMissing(namedArgs, "inf", base + "are");
648 putIfMissing(namedArgs, "aux", aux);
649 putIfMissing(namedArgs, "ger", base + "ando");
650 putIfMissing(namedArgs, "presp", base + "ante");
651 putIfMissing(namedArgs, "pastp", base + "ato");
653 putIfMissing(namedArgs, "pres1s", base + "o");
654 putIfMissing(namedArgs, "pres2s", base + "i");
655 putIfMissing(namedArgs, "pres3s", base + "a");
656 putIfMissing(namedArgs, "pres1p", base + "iamo");
657 putIfMissing(namedArgs, "pres2p", base + "ate");
658 putIfMissing(namedArgs, "pres3p", base + "ano");
660 putIfMissing(namedArgs, "imperf1s", base + "avo");
661 putIfMissing(namedArgs, "imperf2s", base + "avi");
662 putIfMissing(namedArgs, "imperf3s", base + "ava");
663 putIfMissing(namedArgs, "imperf1p", base + "avamo");
664 putIfMissing(namedArgs, "imperf2p", base + "avate");
665 putIfMissing(namedArgs, "imperf3p", base + "avano");
667 putIfMissing(namedArgs, "prem1s", base + "ai");
668 putIfMissing(namedArgs, "prem2s", base + "asti");
669 putIfMissing(namedArgs, "prem3s", base + "ò");
670 putIfMissing(namedArgs, "prem1p", base + "ammo");
671 putIfMissing(namedArgs, "prem2p", base + "aste");
672 putIfMissing(namedArgs, "prem3p", base + "arono");
674 putIfMissing(namedArgs, "fut1s", base + "erò");
675 putIfMissing(namedArgs, "fut2s", base + "erai");
676 putIfMissing(namedArgs, "fut3s", base + "erà");
677 putIfMissing(namedArgs, "fut1p", base + "eremo");
678 putIfMissing(namedArgs, "fut2p", base + "erete");
679 putIfMissing(namedArgs, "fut3p", base + "eranno");
681 putIfMissing(namedArgs, "cond1s", base + "erei");
682 putIfMissing(namedArgs, "cond2s", base + "eresti");
683 putIfMissing(namedArgs, "cond3s", base + "erebbe");
684 putIfMissing(namedArgs, "cond1p", base + "eremmo");
685 putIfMissing(namedArgs, "cond2p", base + "ereste");
686 putIfMissing(namedArgs, "cond3p", base + "erebbero");
687 // Subjunctive / congiuntivo
688 putIfMissing(namedArgs, "sub123s", base + "i");
689 putIfMissing(namedArgs, "sub1p", base + "iamo");
690 putIfMissing(namedArgs, "sub2p", base + "iate");
691 putIfMissing(namedArgs, "sub3p", base + "ino");
692 // Imperfect subjunctive
693 putIfMissing(namedArgs, "impsub12s", base + "assi");
694 putIfMissing(namedArgs, "impsub3s", base + "asse");
695 putIfMissing(namedArgs, "impsub1p", base + "assimo");
696 putIfMissing(namedArgs, "impsub2p", base + "aste");
697 putIfMissing(namedArgs, "impsub3p", base + "assero");
699 putIfMissing(namedArgs, "imp2s", base + "a");
700 putIfMissing(namedArgs, "imp3s", base + "i");
701 putIfMissing(namedArgs, "imp1p", base + "iamo");
702 putIfMissing(namedArgs, "imp2p", base + "ate");
703 putIfMissing(namedArgs, "imp3p", base + "ino");
706 itConj(args, namedArgs);
710 private void itConj(List<String> args, Map<String, String> namedArgs) {
711 // TODO Auto-generated method stub
716 private static void putIfMissing(final Map<String, String> namedArgs, final String key,
717 final String value) {
718 final String oldValue = namedArgs.get(key);
719 if (oldValue == null || oldValue.length() == 0) {
720 namedArgs.put(key, value);
724 // TODO: check how ='' and =| are manifested....
725 // TODO: get this right in -are
726 private static void putOrNullify(final Map<String, String> namedArgs, final String key,
727 final String value) {
728 final String oldValue = namedArgs.get(key);
729 if (oldValue == null/* || oldValue.length() == 0*/) {
730 namedArgs.put(key, value);
732 if (oldValue.equals("''")) {
733 namedArgs.put(key, "");
738 static final Pattern whitespace = Pattern.compile("\\s+");
739 static String trim(final String s) {
740 return whitespace.matcher(s).replaceAll(" ").trim();