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) {
166 boolean done = false;
167 while (wikiTokenizer.nextToken() != null) {
168 if (wikiTokenizer.isHeading()) {
169 wikiTokenizer.returnToLineStart();
176 // Check whether we care about this line:
178 //line = WikiLineReader.removeSquareBrackets(line);
180 if (wikiTokenizer.isFunction()) {
181 final String functionName = wikiTokenizer.functionName();
182 final List<String> positionArgs = wikiTokenizer.functionPositionArgs();
184 if (functionName.equals("trans-top")) {
186 if (wikiTokenizer.functionPositionArgs().size() >= 1) {
187 sense = positionArgs.get(0);
188 // TODO: could emphasize words in [[brackets]] inside sense.
189 sense = WikiTokenizer.toPlainText(sense);
190 //LOG.info("Sense: " + sense);
192 } else if (functionName.equals("trans-bottom")) {
194 } else if (functionName.equals("trans-mid")) {
195 } else if (functionName.equals("trans-see")) {
197 } else if (functionName.startsWith("picdic")) {
198 } else if (functionName.startsWith("checktrans")) {
199 } else if (functionName.startsWith("ttbc")) {
200 wikiTokenizer.nextLine();
201 // TODO: would be great to handle
202 //TODO: Check this: done = true;
204 LOG.warning("Unexpected translation wikifunction: " + wikiTokenizer.token() + ", title=" + title);
206 } else if (wikiTokenizer.isListItem() && wikiTokenizer.listItemPrefix().startsWith("*")) {
207 final String line = wikiTokenizer.listItemWikiText();
208 // This line could produce an output...
210 // First strip the language and check whether it matches.
211 // And hold onto it for sub-lines.
212 final int colonIndex = line.indexOf(":");
213 if (colonIndex == -1) {
217 final String lang = line.substring(0, colonIndex);
218 if (!this.langPattern.matcher(lang).find()) {
222 String rest = line.substring(colonIndex + 1).trim();
223 if (rest.length() > 0) {
224 doTranslationLine(line, title, sense, rest);
226 // TODO: do lines that are like Greek:
229 } else if (wikiTokenizer.remainderStartsWith("''See''")) {
230 wikiTokenizer.nextLine();
231 LOG.fine("Skipping line: " + wikiTokenizer.token());
232 } else if (wikiTokenizer.isWikiLink()) {
233 final String wikiLink = wikiTokenizer.wikiLinkText();
234 if (wikiLink.contains(":") && wikiLink.contains(title)) {
235 } else if (wikiLink.contains("Category:")) {
237 LOG.warning("Unexpected wikiLink: " + wikiTokenizer.token() + ", title=" + title);
239 } else if (wikiTokenizer.isNewline() || wikiTokenizer.isMarkup() || wikiTokenizer.isComment()) {
241 final String token = wikiTokenizer.token();
242 if (token.equals("----")) {
244 LOG.warning("Unexpected translation token: " + wikiTokenizer.token() + ", title=" + title);
251 private static <T> T get(final List<T> list, final int index) {
252 return index < list.size() ? list.get(index) : null;
255 private void doTranslationLine(final String line, final String title, final String sense, final String rest) {
256 // Good chance we'll actually file this one...
257 final PairEntry pairEntry = new PairEntry();
258 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
260 final StringBuilder otherText = new StringBuilder();
261 final WikiTokenizer wikiTokenizer = new WikiTokenizer(rest, false);
262 while (wikiTokenizer.nextToken() != null) {
264 if (wikiTokenizer.isPlainText()) {
265 final String plainText = wikiTokenizer.token();
266 otherText.append("").append(plainText);
267 otherIndexBuilder.addEntryWithString(indexedEntry, plainText, EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
269 } else if (wikiTokenizer.isWikiLink()) {
270 final String plainText = wikiTokenizer.wikiLinkText();
271 otherText.append("").append(plainText);
272 otherIndexBuilder.addEntryWithString(indexedEntry, plainText, EntryTypeName.WIKTIONARY_TRANSLATION_WIKI_TEXT);
274 } else if (wikiTokenizer.isFunction()) {
275 final String functionName = wikiTokenizer.functionName();
276 final List<String> args = wikiTokenizer.functionPositionArgs();
277 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
279 if (functionName.equals("t") || functionName.equals("t+") || functionName.equals("t-") || functionName.equals("tø") || functionName.equals("apdx-t")) {
280 if (args.size() < 2) {
281 LOG.warning("{{t}} with too few args: " + line + ", title=" + title);
284 final String langCode = get(args, 0);
285 //if (this.langCodePattern.matcher(langCode).matches()) {
286 final String word = get(args, 1);
287 final String gender = get(args, 2);
288 final String transliteration = namedArgs.get("tr");
289 if (otherText.length() > 0) {
290 otherText.append("");
292 otherText.append(word);
293 otherIndexBuilder.addEntryWithString(indexedEntry, word, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
294 if (gender != null) {
295 otherText.append(String.format(" {%s}", gender));
297 if (transliteration != null) {
298 otherText.append(String.format(" (tr. %s)", transliteration));
299 otherIndexBuilder.addEntryWithString(indexedEntry, transliteration, EntryTypeName.WIKTIONARY_TRANSLITERATION);
302 } else if (functionName.equals("qualifier")) {
303 String qualifier = args.get(0);
304 if (!namedArgs.isEmpty() || args.size() > 1) {
305 LOG.warning("weird qualifier: " + line);
307 otherText.append("(").append(qualifier).append(")");
308 } else if (encodings.contains(functionName)) {
309 otherText.append("").append(args.get(0));
310 otherIndexBuilder.addEntryWithString(indexedEntry, args.get(0), EntryTypeName.WIKTIONARY_TRANSLATION_OTHER_TEXT);
311 } else if (functionName.equals("m") || functionName.equals("f") || functionName.equals("n") || functionName.equals("p")) {
312 otherText.append("{");
313 otherText.append(functionName);
314 for (int i = 0; i < args.size(); ++i) {
315 otherText.append("|").append(args.get(i));
317 otherText.append("}");
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 } else if (functionName.equals("trreq")) {
337 } else if (functionName.equals("not used")) {
338 otherText.append("(not used)");
339 } else if (functionName.equals("t-image")) {
340 // American sign language
341 } else if (args.isEmpty() && namedArgs.isEmpty()) {
342 otherText.append("{UNK. FUNC.: ").append(functionName).append("}");
344 LOG.warning("Unexpected t+- wikifunction: " + line + ", title=" + title);
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();
383 static final Pattern whitespace = Pattern.compile("\\s+");
385 static String trim(final String s) {
386 return whitespace.matcher(s).replaceAll(" ").trim();
389 Set<String> pairsAdded = new LinkedHashSet<String>();
391 // -------------------------------------------------------------------------
393 private void doForeignWord(final String title, final String text) {
394 final WikiTokenizer wikiTokenizer = new WikiTokenizer(text);
395 while (wikiTokenizer.nextToken() != null) {
396 if (wikiTokenizer.isHeading()) {
397 final String headingName = wikiTokenizer.headingWikiText();
398 if (headingName.equals("Translations")) {
399 LOG.warning("Translations not in English section: " + title);
400 } else if (headingName.equals("Pronunciation")) {
401 //doPronunciation(wikiLineReader);
402 } else if (partOfSpeechHeader.matcher(headingName).matches()) {
403 doPartOfSpeech(title, headingName, wikiTokenizer.headingDepth(), wikiTokenizer);
411 private void doPartOfSpeech(String title, final String posHeading, final int posDepth, WikiTokenizer wikiTokenizer) {
412 LOG.info("***" + title + ", pos=" + posHeading);
413 //final StringBuilder foreignBuilder = new StringBuilder();
416 Collection<String> forms = Collections.emptyList();
418 int currentHeadingDepth = posDepth;
419 while (wikiTokenizer.nextToken() != null) {
420 if (wikiTokenizer.isHeading()) {
421 currentHeadingDepth = wikiTokenizer.headingDepth();
423 if (currentHeadingDepth <= posDepth) {
424 wikiTokenizer.returnToLineStart();
429 if (currentHeadingDepth > posDepth) {
434 if (wikiTokenizer.isFunction()) {
435 final String name = wikiTokenizer.functionName();
436 final List<String> args = wikiTokenizer.functionPositionArgs();
437 final Map<String,String> namedArgs = wikiTokenizer.functionNamedArgs();
438 // First line is generally a repeat of the title with some extra information.
439 // We need to build up the left side (foreign text, tokens) separately from the
440 // right side (English). The left-side may get paired with multiple right sides.
441 // The left side should get filed under every form of the word in question (singular, plural).
443 // For verbs, the conjugation comes later on in a deeper section.
444 // Ideally, we'd want to file every English entry with the verb
445 // under every verb form coming from the conjugation.
446 // Ie. under "fa": see: "make :: fare" and "do :: fare"
447 // But then where should we put the conjugation table?
448 // 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!)
449 // for the conjugation table from "fa".
450 // Would like to be able to link to a lang#token.
451 if (name.equals("it-noun")) {
452 assert forms.isEmpty();
453 final String base = get(args, 0);
454 final String gender = get(args, 1);
455 final String singular = base + get(args, 2);
456 final String plural = base + get(args, 3);
457 side = String.format("%s {%s}, %s {pl}", singular, gender, plural, plural);
458 forms = Arrays.asList(singular, plural);
459 } else if (name.equals("it-proper noun")) {
461 } else if (name.equals("it-adj")) {
463 } else if (name.startsWith("it-conj")) {
464 if (name.equals("it-conj-are")) {
465 itConjAre(args, namedArgs);
466 } else if (name.equals("it-conj-ere")) {
467 } else if (name.equals("it-conj-ire")) {
469 LOG.warning("Unknown conjugation: " + wikiTokenizer.token());
473 LOG.warning("Unknown function: " + wikiTokenizer.token());
476 } else if (wikiTokenizer.isListItem()) {
477 handleForeignListItem(side != null ? side : title, title, forms, wikiTokenizer);
479 } else if (wikiTokenizer.isWikiLink()) {
487 private void itConjAre(List<String> args, Map<String, String> namedArgs) {
488 final String base = args.get(0);
489 final String aux = args.get(1);
491 putIfMissing(namedArgs, "inf", base + "are");
492 putIfMissing(namedArgs, "aux", aux);
493 putIfMissing(namedArgs, "ger", base + "ando");
494 putIfMissing(namedArgs, "presp", base + "ante");
495 putIfMissing(namedArgs, "pastp", base + "ato");
497 putIfMissing(namedArgs, "pres1s", base + "o");
498 putIfMissing(namedArgs, "pres2s", base + "i");
499 putIfMissing(namedArgs, "pres3s", base + "a");
500 putIfMissing(namedArgs, "pres1p", base + "iamo");
501 putIfMissing(namedArgs, "pres2p", base + "ate");
502 putIfMissing(namedArgs, "pres3p", base + "ano");
504 putIfMissing(namedArgs, "imperf1s", base + "avo");
505 putIfMissing(namedArgs, "imperf2s", base + "avi");
506 putIfMissing(namedArgs, "imperf3s", base + "ava");
507 putIfMissing(namedArgs, "imperf1p", base + "avamo");
508 putIfMissing(namedArgs, "imperf2p", base + "avate");
509 putIfMissing(namedArgs, "imperf3p", base + "avano");
511 putIfMissing(namedArgs, "prem1s", base + "ai");
512 putIfMissing(namedArgs, "prem2s", base + "asti");
513 putIfMissing(namedArgs, "prem3s", base + "ò");
514 putIfMissing(namedArgs, "prem1p", base + "ammo");
515 putIfMissing(namedArgs, "prem2p", base + "aste");
516 putIfMissing(namedArgs, "prem3p", base + "arono");
518 putIfMissing(namedArgs, "fut1s", base + "erò");
519 putIfMissing(namedArgs, "fut2s", base + "erai");
520 putIfMissing(namedArgs, "fut3s", base + "erà");
521 putIfMissing(namedArgs, "fut1p", base + "eremo");
522 putIfMissing(namedArgs, "fut2p", base + "erete");
523 putIfMissing(namedArgs, "fut3p", base + "eranno");
525 putIfMissing(namedArgs, "cond1s", base + "erei");
526 putIfMissing(namedArgs, "cond2s", base + "eresti");
527 putIfMissing(namedArgs, "cond3s", base + "erebbe");
528 putIfMissing(namedArgs, "cond1p", base + "eremmo");
529 putIfMissing(namedArgs, "cond2p", base + "ereste");
530 putIfMissing(namedArgs, "cond3p", base + "erebbero");
531 // Subjunctive / congiuntivo
532 putIfMissing(namedArgs, "sub123s", base + "i");
533 putIfMissing(namedArgs, "sub1p", base + "iamo");
534 putIfMissing(namedArgs, "sub2p", base + "iate");
535 putIfMissing(namedArgs, "sub3p", base + "ino");
536 // Imperfect subjunctive
537 putIfMissing(namedArgs, "impsub12s", base + "assi");
538 putIfMissing(namedArgs, "impsub3s", base + "asse");
539 putIfMissing(namedArgs, "impsub1p", base + "assimo");
540 putIfMissing(namedArgs, "impsub2p", base + "aste");
541 putIfMissing(namedArgs, "impsub3p", base + "assero");
543 putIfMissing(namedArgs, "imp2s", base + "a");
544 putIfMissing(namedArgs, "imp3s", base + "i");
545 putIfMissing(namedArgs, "imp1p", base + "iamo");
546 putIfMissing(namedArgs, "imp2p", base + "ate");
547 putIfMissing(namedArgs, "imp3p", base + "ino");
550 itConj(args, namedArgs);
554 private void itConj(List<String> args, Map<String, String> namedArgs) {
555 // TODO Auto-generated method stub
560 private static void putIfMissing(final Map<String, String> namedArgs, final String key,
561 final String value) {
562 final String oldValue = namedArgs.get(key);
563 if (oldValue == null || oldValue.length() == 0) {
564 namedArgs.put(key, value);
568 // TODO: check how ='' and =| are manifested....
569 // TODO: get this right in -are
570 private static void putOrNullify(final Map<String, String> namedArgs, final String key,
571 final String value) {
572 final String oldValue = namedArgs.get(key);
573 if (oldValue == null/* || oldValue.length() == 0*/) {
574 namedArgs.put(key, value);
576 if (oldValue.equals("''")) {
577 namedArgs.put(key, "");
582 final List<String> listPrefixes = new ArrayList<String>();
583 final List<String> listLines = new ArrayList<String>();
585 static final Pattern UNINDEXED_WIKI_TEXT = Pattern.compile(
586 "(first|second|third)-person (singular|plural)|" +
591 private void handleForeignListItem(final String foreignText, String title, final Collection<String> forms, final WikiTokenizer wikiTokenizer) {
593 final String prefix = wikiTokenizer.listItemPrefix();
594 if (prefix.length() > 1) {
595 LOG.warning("Prefix too long: " + wikiTokenizer.token());
599 listPrefixes.clear();
601 listPrefixes.add(prefix);
602 listLines.add(wikiTokenizer.listItemWikiText());
603 while(wikiTokenizer.nextToken() != null &&
604 wikiTokenizer.isNewline() ||
605 wikiTokenizer.isComment() ||
606 (wikiTokenizer.isListItem() &&
607 wikiTokenizer.listItemPrefix().length() > prefix.length() &&
608 wikiTokenizer.listItemPrefix().startsWith(prefix))) {
609 if (wikiTokenizer.isListItem()) {
610 listPrefixes.add(wikiTokenizer.listItemPrefix());
611 listLines.add(wikiTokenizer.listItemWikiText());
614 if (wikiTokenizer.nextToken() != null) {
615 wikiTokenizer.returnToLineStart();
617 LOG.info("list lines: " + listLines);
618 LOG.info("list prefixes: " + listPrefixes);
620 final PairEntry pairEntry = new PairEntry();
621 final IndexedEntry indexedEntry = new IndexedEntry(pairEntry);
623 final String foreign = trim(title);
625 final StringBuilder englishBuilder = new StringBuilder();
627 final String mainLine = listLines.get(0);
629 final WikiTokenizer englishTokenizer = new WikiTokenizer(mainLine, false);
630 while (englishTokenizer.nextToken() != null) {
631 // TODO handle form of....
632 if (englishTokenizer.isPlainText()) {
633 englishBuilder.append(englishTokenizer.token());
634 enIndexBuilder.addEntryWithString(indexedEntry, englishTokenizer.token(), EntryTypeName.WIKTIONARY_ENGLISH_DEF);
635 } else if (englishTokenizer.isWikiLink()) {
636 final String text = englishTokenizer.wikiLinkText();
637 final String link = englishTokenizer.wikiLinkDest();
639 if (link.contains("#English")) {
640 englishBuilder.append(text);
641 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
642 } else if (link.contains("#") && this.langPattern.matcher(link).find()) {
643 englishBuilder.append(text);
644 otherIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_OTHER_LANG);
646 LOG.warning("Special link: " + englishTokenizer.token());
647 // TODO: something here...
651 englishBuilder.append(text);
652 if (!UNINDEXED_WIKI_TEXT.matcher(text).find()) {
653 enIndexBuilder.addEntryWithString(indexedEntry, text, EntryTypeName.WIKTIONARY_ENGLISH_DEF_WIKI_LINK);
656 } else if (englishTokenizer.isFunction()) {
657 final String name = englishTokenizer.functionName();
658 if (name.contains(" conjugation of ") ||
659 name.contains(" form of ") ||
660 name.contains(" feminine of ") ||
661 name.contains(" plural of ")) {
662 // Ignore these in the index, they're really annoying....
663 englishBuilder.append(englishTokenizer.token());
665 LOG.warning("Unexpected function: " + englishTokenizer.token());
668 if (englishTokenizer.isComment() || englishTokenizer.isMarkup()) {
670 LOG.warning("Unexpected definition text: " + englishTokenizer.token());
674 final String english = trim(englishBuilder.toString());
675 if (english.length() > 0) {
676 final Pair pair = new Pair(english, trim(foreignText), this.swap);
677 pairEntry.pairs.add(pair);
678 otherIndexBuilder.addEntryWithString(indexedEntry, title, EntryTypeName.WIKTIONARY_TITLE_SINGLE, EntryTypeName.WIKTIONARY_TITLE_MULTI);
679 for (final String form : forms) {
680 otherIndexBuilder.addEntryWithString(indexedEntry, form, EntryTypeName.WIKTIONARY_FORM_SINGLE, EntryTypeName.WIKTIONARY_FORM_MULTI);