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.enwiktionary;
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.LinkedHashSet;
27 import java.util.List;
30 import java.util.logging.Logger;
31 import java.util.regex.Pattern;
33 import com.hughes.android.dictionary.engine.EntryTypeName;
34 import com.hughes.android.dictionary.engine.IndexBuilder;
35 import com.hughes.android.dictionary.engine.IndexedEntry;
36 import com.hughes.android.dictionary.engine.PairEntry;
37 import com.hughes.android.dictionary.engine.PairEntry.Pair;
38 import com.hughes.android.dictionary.parser.WikiTokenizer;
40 public class EnWiktionaryXmlParser {
42 static final Logger LOG = Logger.getLogger(EnWiktionaryXmlParser.class.getName());
44 // TODO: process {{ttbc}} lines
46 static final Pattern partOfSpeechHeader = Pattern.compile(
47 "Noun|Verb|Adjective|Adverb|Pronoun|Conjunction|Interjection|" +
48 "Preposition|Proper noun|Article|Prepositional phrase|Acronym|" +
49 "Abbreviation|Initialism|Contraction|Prefix|Suffix|Symbol|Letter|" +
50 "Ligature|Idiom|Phrase|\\{\\{acronym\\}\\}|\\{\\{initialism\\}\\}|" +
51 "\\{\\{abbreviation\\}\\}|" +
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 foreignIndexBuilder;
62 final Pattern langPattern;
63 final Pattern langCodePattern;
66 // State used while parsing.
69 ENGLISH_DEF_OF_FOREIGN,
76 public EnWiktionaryXmlParser(final IndexBuilder enIndexBuilder, final IndexBuilder otherIndexBuilder, final Pattern langPattern, final Pattern langCodePattern, final boolean swap) {
77 this.enIndexBuilder = enIndexBuilder;
78 this.foreignIndexBuilder = otherIndexBuilder;
79 this.langPattern = langPattern;
80 this.langCodePattern = langCodePattern;
85 public void parse(final File file, final int pageLimit) throws IOException {
87 final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
89 if (pageLimit >= 0 && pageCount >= pageLimit) {
94 title = dis.readUTF();
95 } catch (EOFException e) {
96 LOG.warning("Error reading split!");
100 final String heading = dis.readUTF();
101 final int bytesLength = dis.readInt();
102 final byte[] bytes = new byte[bytesLength];
103 dis.readFully(bytes);
104 final String text = new String(bytes, "UTF8");
106 parseSection(heading, text);
109 if (pageCount % 1000 == 0) {
110 LOG.info("pageCount=" + pageCount);
115 private void parseSection(String heading, final String text) {
116 if (title.startsWith("Wiktionary:") ||
117 title.startsWith("Template:") ||
118 title.startsWith("Appendix:") ||
119 title.startsWith("Category:") ||
120 title.startsWith("Index:") ||
121 title.startsWith("MediaWiki:") ||
122 title.startsWith("TransWiki:") ||
123 title.startsWith("Citations:") ||
124 title.startsWith("Concordance:") ||
125 title.startsWith("Help:")) {
129 heading = heading.replaceAll("=", "").trim();
130 if (heading.equals("English")) {
132 } else if (langPattern.matcher(heading).find()){
133 doForeignWord(heading, text);
138 // -------------------------------------------------------------------------
140 private void doEnglishWord(String text) {
145 final WikiTokenizer wikiTokenizer = new WikiTokenizer(text);
146 while (wikiTokenizer.nextToken() != null) {
148 if (wikiTokenizer.isHeading()) {
149 final String headerName = wikiTokenizer.headingWikiText();
151 if (wikiTokenizer.headingDepth() <= posDepth) {
156 if (partOfSpeechHeader.matcher(headerName).matches()) {
157 posDepth = wikiTokenizer.headingDepth();
158 pos = wikiTokenizer.headingWikiText();
159 // TODO: if we're inside the POS section, we should handle the first title line...
161 } else if (headerName.equals("Translations")) {
163 LOG.info("Translations without POS (but using anyway): " + title);
165 doTranslations(wikiTokenizer, pos);
166 } else if (headerName.equals("Pronunciation")) {
167 //doPronunciation(wikiLineReader);
169 } else if (wikiTokenizer.isFunction()) {
170 final String name = wikiTokenizer.functionName();
171 if (name.equals("head") && pos == null) {
172 LOG.warning("{{head}} without POS: " + title);
178 final AppendAndIndexWikiCallback appendAndIndexWikiCallback = new AppendAndIndexWikiCallback(this);
180 appendAndIndexWikiCallback.functionCallbacks.putAll(FunctionCallbacksDefault.DEFAULT);
183 private void doTranslations(final WikiTokenizer wikiTokenizer, final String pos) {
184 if (title.equals("absolutely")) {
185 //System.out.println();
188 String topLevelLang = null;
190 boolean done = false;
191 while (wikiTokenizer.nextToken() != null) {
192 if (wikiTokenizer.isHeading()) {
193 wikiTokenizer.returnToLineStart();
200 // Check whether we care about this line:
202 if (wikiTokenizer.isFunction()) {
203 final String functionName = wikiTokenizer.functionName();
204 final List<String> positionArgs = wikiTokenizer.functionPositionArgs();
206 if (functionName.equals("trans-top")) {
208 if (wikiTokenizer.functionPositionArgs().size() >= 1) {
209 sense = positionArgs.get(0);
210 // TODO: could emphasize words in [[brackets]] inside sense.
211 sense = WikiTokenizer.toPlainText(sense);
212 //LOG.info("Sense: " + sense);
214 } else if (functionName.equals("trans-bottom")) {
216 } else if (functionName.equals("trans-mid")) {
217 } else if (functionName.equals("trans-see")) {
218 // TODO: would also be nice...
219 } else if (functionName.startsWith("picdic")) {
220 } else if (functionName.startsWith("checktrans")) {
222 } else if (functionName.startsWith("ttbc")) {
223 wikiTokenizer.nextLine();
224 // TODO: would be great to handle ttbc
225 // TODO: Check this: done = true;
227 LOG.warning("Unexpected translation wikifunction: " + wikiTokenizer.token() + ", title=" + title);
229 } else if (wikiTokenizer.isListItem()) {
230 final String line = wikiTokenizer.listItemWikiText();
231 // This line could produce an output...
233 if (line.contains("ich hoan dich gear")) {
234 //System.out.println();
237 // First strip the language and check whether it matches.
238 // And hold onto it for sub-lines.
239 final int colonIndex = line.indexOf(":");
240 if (colonIndex == -1) {
244 final String lang = trim(WikiTokenizer.toPlainText(line.substring(0, colonIndex)));
245 final boolean appendLang;
246 if (wikiTokenizer.listItemPrefix().length() == 1) {
248 final boolean thisFind = langPattern.matcher(lang).find();
252 appendLang = !langPattern.matcher(lang).matches();
253 } else if (topLevelLang == null) {
256 // Two-level -- the only way we won't append is if this second level matches exactly.
257 if (!langPattern.matcher(lang).matches() && !langPattern.matcher(topLevelLang).find()) {
260 appendLang = !langPattern.matcher(lang).matches();
263 String rest = line.substring(colonIndex + 1).trim();
264 if (rest.length() > 0) {
265 doTranslationLine(line, appendLang ? lang : null, pos, sense, rest);
268 } else if (wikiTokenizer.remainderStartsWith("''See''")) {
269 wikiTokenizer.nextLine();
270 LOG.fine("Skipping See line: " + wikiTokenizer.token());
271 } else if (wikiTokenizer.isWikiLink()) {
272 final String wikiLink = wikiTokenizer.wikiLinkText();
273 if (wikiLink.contains(":") && wikiLink.contains(title)) {
274 } else if (wikiLink.contains("Category:")) {
276 LOG.warning("Unexpected wikiLink: " + wikiTokenizer.token() + ", title=" + title);
278 } else if (wikiTokenizer.isNewline() || wikiTokenizer.isMarkup() || wikiTokenizer.isComment()) {
280 final String token = wikiTokenizer.token();
281 if (token.equals("----")) {
283 LOG.warning("Unexpected translation token: " + wikiTokenizer.token() + ", title=" + title);
290 private void doTranslationLine(final String line, final String lang, final String pos, final String sense, final String rest) {
291 state = State.TRANSLATION_LINE;
292 // Good chance we'll actually file this one...
293 final PairEntry pairEntry = new PairEntry();
294 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
296 final StringBuilder foreignText = new StringBuilder();
297 appendAndIndexWikiCallback.reset(foreignText, indexedEntry);
298 appendAndIndexWikiCallback.dispatch(rest, foreignIndexBuilder, EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
300 if (foreignText.length() == 0) {
301 LOG.warning("Empty foreignText: " + line);
306 foreignText.insert(0, String.format("(%s) ", lang));
309 StringBuilder englishText = new StringBuilder();
311 englishText.append(title);
313 englishText.append(" (").append(sense).append(")");
314 enIndexBuilder.addEntryWithString(indexedEntry, sense, EntryTypeName.WIKTIONARY_TRANSLATION_SENSE);
317 englishText.append(" (").append(pos.toLowerCase()).append(")");
319 enIndexBuilder.addEntryWithString(indexedEntry, title, EntryTypeName.WIKTIONARY_TITLE_MULTI);
321 final Pair pair = new Pair(trim(englishText.toString()), trim(foreignText.toString()), swap);
322 pairEntry.pairs.add(pair);
323 if (!pairsAdded.add(pair.toString())) {
324 LOG.warning("Duplicate pair: " + pair.toString());
329 Set<String> pairsAdded = new LinkedHashSet<String>();
331 // -------------------------------------------------------------------------
333 private void doForeignWord(final String lang, final String text) {
334 final WikiTokenizer wikiTokenizer = new WikiTokenizer(text);
335 while (wikiTokenizer.nextToken() != null) {
336 if (wikiTokenizer.isHeading()) {
337 final String headingName = wikiTokenizer.headingWikiText();
338 if (headingName.equals("Translations")) {
339 LOG.warning("Translations not in English section: " + title);
340 } else if (headingName.equals("Pronunciation")) {
341 //doPronunciation(wikiLineReader);
342 } else if (partOfSpeechHeader.matcher(headingName).matches()) {
343 doForeignPartOfSpeech(lang, headingName, wikiTokenizer.headingDepth(), wikiTokenizer);
350 static final class ListSection {
351 final String firstPrefix;
352 final String firstLine;
353 final List<String> nextPrefixes = new ArrayList<String>();
354 final List<String> nextLines = new ArrayList<String>();
356 public ListSection(String firstPrefix, String firstLine) {
357 this.firstPrefix = firstPrefix;
358 this.firstLine = firstLine;
362 public String toString() {
363 return firstPrefix + firstLine + "{ " + nextPrefixes + "}";
368 int foreignCount = 0;
369 final Collection<String> wordForms = new ArrayList<String>();
370 boolean titleAppended = false;
372 private void doForeignPartOfSpeech(final String lang, String posHeading, final int posDepth, WikiTokenizer wikiTokenizer) {
373 if (++foreignCount % 1000 == 0) {
374 LOG.info("***" + lang + ", " + title + ", pos=" + posHeading + ", foreignCount=" + foreignCount);
376 if (title.equals("6")) {
377 System.out.println();
380 final StringBuilder foreignBuilder = new StringBuilder();
381 final List<ListSection> listSections = new ArrayList<ListSection>();
383 appendAndIndexWikiCallback.reset(foreignBuilder, null);
384 this.state = State.ENGLISH_DEF_OF_FOREIGN; // TODO: this is wrong, need new category....
385 titleAppended = false;
390 ListSection lastListSection = null;
392 int currentHeadingDepth = posDepth;
393 while (wikiTokenizer.nextToken() != null) {
394 if (wikiTokenizer.isHeading()) {
395 currentHeadingDepth = wikiTokenizer.headingDepth();
397 if (currentHeadingDepth <= posDepth) {
398 wikiTokenizer.returnToLineStart();
403 if (currentHeadingDepth > posDepth) {
404 // TODO: deal with other neat info sections
408 if (wikiTokenizer.isFunction()) {
409 final String name = wikiTokenizer.functionName();
410 final List<String> args = wikiTokenizer.functionPositionArgs();
411 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
412 // First line is generally a repeat of the title with some extra information.
413 // We need to build up the left side (foreign text, tokens) separately from the
414 // right side (English). The left-side may get paired with multiple right sides.
415 // The left side should get filed under every form of the word in question (singular, plural).
417 // For verbs, the conjugation comes later on in a deeper section.
418 // Ideally, we'd want to file every English entry with the verb
419 // under every verb form coming from the conjugation.
420 // Ie. under "fa": see: "make :: fare" and "do :: fare"
421 // But then where should we put the conjugation table?
422 // 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!)
423 // for the conjugation table from "fa".
424 // Would like to be able to link to a lang#token.
426 appendAndIndexWikiCallback.onFunction(wikiTokenizer, name, args, namedArgs);
428 } else if (wikiTokenizer.isListItem()) {
429 final String prefix = wikiTokenizer.listItemPrefix();
430 if (lastListSection != null &&
431 prefix.startsWith(lastListSection.firstPrefix) &&
432 prefix.length() > lastListSection.firstPrefix.length()) {
433 lastListSection.nextPrefixes.add(prefix);
434 lastListSection.nextLines.add(wikiTokenizer.listItemWikiText());
436 lastListSection = new ListSection(prefix, wikiTokenizer.listItemWikiText());
437 listSections.add(lastListSection);
439 } else if (lastListSection != null) {
440 // Don't append anything after the lists, because there's crap.
441 } else if (wikiTokenizer.isWikiLink()) {
443 foreignBuilder.append(wikiTokenizer.wikiLinkText());
445 } else if (wikiTokenizer.isPlainText()) {
447 foreignBuilder.append(wikiTokenizer.token());
449 } else if (wikiTokenizer.isMarkup() || wikiTokenizer.isNewline() || wikiTokenizer.isComment()) {
452 LOG.warning("Unexpected token: " + wikiTokenizer.token());
457 // Here's where we exit.
458 // Should we make an entry even if there are no foreign list items?
459 String foreign = foreignBuilder.toString().trim();
460 if (!titleAppended && !foreign.toLowerCase().startsWith(title.toLowerCase())) {
461 foreign = String.format("%s %s", title, foreign);
463 if (!langPattern.matcher(lang).matches()) {
464 foreign = String.format("(%s) %s", lang, foreign);
466 for (final ListSection listSection : listSections) {
467 doForeignListSection(foreign, title, wordForms, listSection);
473 // Might only want to remove "lang" if it's equal to "zh", for example.
474 static final Set<String> USELESS_WIKI_ARGS = new LinkedHashSet<String>(
483 public boolean entryIsFormOfSomething = false;
485 private void doForeignListSection(final String foreignText, String title, final Collection<String> forms, final ListSection listSection) {
486 state = State.ENGLISH_DEF_OF_FOREIGN;
487 final String prefix = listSection.firstPrefix;
488 if (prefix.length() > 1) {
489 // Could just get looser and say that any prefix longer than first is a sublist.
490 LOG.warning("Prefix too long: " + listSection);
494 final PairEntry pairEntry = new PairEntry();
495 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
497 entryIsFormOfSomething = false;
498 final StringBuilder englishBuilder = new StringBuilder();
499 final String mainLine = listSection.firstLine;
500 appendAndIndexWikiCallback.reset(englishBuilder, indexedEntry);
501 appendAndIndexWikiCallback.dispatch(mainLine, enIndexBuilder, EntryTypeName.WIKTIONARY_ENGLISH_DEF);
503 final String english = trim(englishBuilder.toString());
504 if (english.length() > 0) {
505 final Pair pair = new Pair(english, trim(foreignText), this.swap);
506 pairEntry.pairs.add(pair);
507 foreignIndexBuilder.addEntryWithString(indexedEntry, title, entryIsFormOfSomething ? EntryTypeName.WIKTIONARY_IS_FORM_OF_SOMETHING_ELSE : EntryTypeName.WIKTIONARY_TITLE_MULTI);
508 for (final String form : forms) {
509 foreignIndexBuilder.addEntryWithString(indexedEntry, form, EntryTypeName.WIKTIONARY_INFLECTED_FORM_MULTI);
514 String lastForeign = null;
515 for (int i = 0; i < listSection.nextPrefixes.size(); ++i) {
516 final String nextPrefix = listSection.nextPrefixes.get(i);
517 final String nextLine = listSection.nextLines.get(i);
519 // TODO: This splitting is not sensitive to wiki code.
520 int dash = nextLine.indexOf("—");
523 dash = nextLine.indexOf("—");
527 dash = nextLine.indexOf(" - ");
531 if ((nextPrefix.equals("#:") || nextPrefix.equals("##:")) && dash != -1) {
532 final String foreignEx = nextLine.substring(0, dash);
533 final String englishEx = nextLine.substring(dash + mdashLen);
534 final Pair pair = new Pair(formatAndIndexExampleString(englishEx, enIndexBuilder, indexedEntry), formatAndIndexExampleString(foreignEx, foreignIndexBuilder, indexedEntry), swap);
535 if (pair.lang1 != "--" && pair.lang1 != "--") {
536 pairEntry.pairs.add(pair);
539 } else if (nextPrefix.equals("#:") || nextPrefix.equals("##:")){
540 final Pair pair = new Pair("--", formatAndIndexExampleString(nextLine, null, indexedEntry), swap);
541 lastForeign = nextLine;
542 if (pair.lang1 != "--" && pair.lang1 != "--") {
543 pairEntry.pairs.add(pair);
545 } else if (nextPrefix.equals("#::") || nextPrefix.equals("#**")) {
546 if (lastForeign != null && pairEntry.pairs.size() > 0) {
547 pairEntry.pairs.remove(pairEntry.pairs.size() - 1);
548 final Pair pair = new Pair(formatAndIndexExampleString(nextLine, enIndexBuilder, indexedEntry), formatAndIndexExampleString(lastForeign, foreignIndexBuilder, indexedEntry), swap);
549 if (pair.lang1 != "--" || pair.lang2 != "--") {
550 pairEntry.pairs.add(pair);
554 LOG.warning("TODO: English example with no foreign: " + title + ", " + nextLine);
555 final Pair pair = new Pair("--", formatAndIndexExampleString(nextLine, null, indexedEntry), swap);
556 if (pair.lang1 != "--" || pair.lang2 != "--") {
557 pairEntry.pairs.add(pair);
560 } else if (nextPrefix.equals("#*")) {
561 // Can't really index these.
562 final Pair pair = new Pair("--", formatAndIndexExampleString(nextLine, null, indexedEntry), swap);
563 lastForeign = nextLine;
564 if (pair.lang1 != "--" || pair.lang2 != "--") {
565 pairEntry.pairs.add(pair);
567 } else if (nextPrefix.equals("#::*") || nextPrefix.equals("##") || nextPrefix.equals("#*:") || nextPrefix.equals("#:*") || true) {
568 final Pair pair = new Pair("--", formatAndIndexExampleString(nextLine, null, indexedEntry), swap);
569 if (pair.lang1 != "--" || pair.lang2 != "--") {
570 pairEntry.pairs.add(pair);
578 private String formatAndIndexExampleString(final String example, final IndexBuilder indexBuilder, final IndexedEntry indexedEntry) {
580 // if (wikiTokenizer.token().equals("'''")) {
581 // insideTripleQuotes = !insideTripleQuotes;
583 final StringBuilder builder = new StringBuilder();
584 appendAndIndexWikiCallback.reset(builder, indexedEntry);
585 appendAndIndexWikiCallback.entryTypeName = EntryTypeName.WIKTIONARY_EXAMPLE;
586 appendAndIndexWikiCallback.entryTypeNameSticks = true;
588 // TODO: this is a hack needed because we don't safely split on the dash.
589 appendAndIndexWikiCallback.dispatch(example, indexBuilder, EntryTypeName.WIKTIONARY_EXAMPLE);
590 } catch (AssertionError e) {
593 final String result = trim(builder.toString());
594 return result.length() > 0 ? result : "--";
598 private void itConjAre(List<String> args, Map<String, String> namedArgs) {
599 final String base = args.get(0);
600 final String aux = args.get(1);
602 putIfMissing(namedArgs, "inf", base + "are");
603 putIfMissing(namedArgs, "aux", aux);
604 putIfMissing(namedArgs, "ger", base + "ando");
605 putIfMissing(namedArgs, "presp", base + "ante");
606 putIfMissing(namedArgs, "pastp", base + "ato");
608 putIfMissing(namedArgs, "pres1s", base + "o");
609 putIfMissing(namedArgs, "pres2s", base + "i");
610 putIfMissing(namedArgs, "pres3s", base + "a");
611 putIfMissing(namedArgs, "pres1p", base + "iamo");
612 putIfMissing(namedArgs, "pres2p", base + "ate");
613 putIfMissing(namedArgs, "pres3p", base + "ano");
615 putIfMissing(namedArgs, "imperf1s", base + "avo");
616 putIfMissing(namedArgs, "imperf2s", base + "avi");
617 putIfMissing(namedArgs, "imperf3s", base + "ava");
618 putIfMissing(namedArgs, "imperf1p", base + "avamo");
619 putIfMissing(namedArgs, "imperf2p", base + "avate");
620 putIfMissing(namedArgs, "imperf3p", base + "avano");
622 putIfMissing(namedArgs, "prem1s", base + "ai");
623 putIfMissing(namedArgs, "prem2s", base + "asti");
624 putIfMissing(namedArgs, "prem3s", base + "ò");
625 putIfMissing(namedArgs, "prem1p", base + "ammo");
626 putIfMissing(namedArgs, "prem2p", base + "aste");
627 putIfMissing(namedArgs, "prem3p", base + "arono");
629 putIfMissing(namedArgs, "fut1s", base + "erò");
630 putIfMissing(namedArgs, "fut2s", base + "erai");
631 putIfMissing(namedArgs, "fut3s", base + "erà");
632 putIfMissing(namedArgs, "fut1p", base + "eremo");
633 putIfMissing(namedArgs, "fut2p", base + "erete");
634 putIfMissing(namedArgs, "fut3p", base + "eranno");
636 putIfMissing(namedArgs, "cond1s", base + "erei");
637 putIfMissing(namedArgs, "cond2s", base + "eresti");
638 putIfMissing(namedArgs, "cond3s", base + "erebbe");
639 putIfMissing(namedArgs, "cond1p", base + "eremmo");
640 putIfMissing(namedArgs, "cond2p", base + "ereste");
641 putIfMissing(namedArgs, "cond3p", base + "erebbero");
642 // Subjunctive / congiuntivo
643 putIfMissing(namedArgs, "sub123s", base + "i");
644 putIfMissing(namedArgs, "sub1p", base + "iamo");
645 putIfMissing(namedArgs, "sub2p", base + "iate");
646 putIfMissing(namedArgs, "sub3p", base + "ino");
647 // Imperfect subjunctive
648 putIfMissing(namedArgs, "impsub12s", base + "assi");
649 putIfMissing(namedArgs, "impsub3s", base + "asse");
650 putIfMissing(namedArgs, "impsub1p", base + "assimo");
651 putIfMissing(namedArgs, "impsub2p", base + "aste");
652 putIfMissing(namedArgs, "impsub3p", base + "assero");
654 putIfMissing(namedArgs, "imp2s", base + "a");
655 putIfMissing(namedArgs, "imp3s", base + "i");
656 putIfMissing(namedArgs, "imp1p", base + "iamo");
657 putIfMissing(namedArgs, "imp2p", base + "ate");
658 putIfMissing(namedArgs, "imp3p", base + "ino");
661 itConj(args, namedArgs);
665 private void itConj(List<String> args, Map<String, String> namedArgs) {
666 // TODO Auto-generated method stub
671 private static void putIfMissing(final Map<String, String> namedArgs, final String key,
672 final String value) {
673 final String oldValue = namedArgs.get(key);
674 if (oldValue == null || oldValue.length() == 0) {
675 namedArgs.put(key, value);
679 // TODO: check how ='' and =| are manifested....
680 // TODO: get this right in -are
681 private static void putOrNullify(final Map<String, String> namedArgs, final String key,
682 final String value) {
683 final String oldValue = namedArgs.get(key);
684 if (oldValue == null/* || oldValue.length() == 0*/) {
685 namedArgs.put(key, value);
687 if (oldValue.equals("''")) {
688 namedArgs.put(key, "");
693 static final Pattern whitespace = Pattern.compile("\\s+");
694 static String trim(final String s) {
695 return whitespace.matcher(s).replaceAll(" ").trim();