X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fparser%2Fenwiktionary%2FAppendAndIndexWikiCallback.java;h=82e345ce41b6cf9fa1c774638d7da33136c87196;hb=52887b59a691a06638ce7ecf75064dc34c55701b;hp=4a48a61100384a3b24789e389829645d0446cc2b;hpb=d06b99b469b18cfa4a8a4bd45d51ee4ebd7efaca;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/parser/enwiktionary/AppendAndIndexWikiCallback.java b/src/com/hughes/android/dictionary/parser/enwiktionary/AppendAndIndexWikiCallback.java index 4a48a61..82e345c 100644 --- a/src/com/hughes/android/dictionary/parser/enwiktionary/AppendAndIndexWikiCallback.java +++ b/src/com/hughes/android/dictionary/parser/enwiktionary/AppendAndIndexWikiCallback.java @@ -1,3 +1,17 @@ +// Copyright 2012 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package com.hughes.android.dictionary.parser.enwiktionary; import java.util.LinkedHashMap; @@ -18,6 +32,7 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback { IndexBuilder indexBuilder; final Map functionCallbacks = new LinkedHashMap(); + boolean entryTypeNameSticks = false; EntryTypeName entryTypeName = null; public AppendAndIndexWikiCallback(final EnWiktionaryXmlParser parser) { @@ -29,13 +44,16 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback { this.indexedEntry = indexedEntry; this.indexBuilder = null; entryTypeName = null; + entryTypeNameSticks = false; } public void dispatch(final String wikiText, final IndexBuilder indexBuilder, final EntryTypeName entryTypeName) { final IndexBuilder oldIndexBuilder = this.indexBuilder; final EntryTypeName oldEntryTypeName = this.entryTypeName; this.indexBuilder = indexBuilder; - this.entryTypeName = EnumUtil.min(entryTypeName, this.entryTypeName); + if (!entryTypeNameSticks) { + this.entryTypeName = EnumUtil.min(entryTypeName, this.entryTypeName); + } if (entryTypeName == null) this.entryTypeName = null; WikiTokenizer.dispatch(wikiText, false, this); this.indexBuilder = oldIndexBuilder; @@ -96,17 +114,6 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback { final Map namedArgs) { FunctionCallback functionCallback = functionCallbacks.get(name); - if (functionCallback == null) { - if ( - name.equals("form of") || // TODO: switch to contains - name.contains("conjugation of") || - name.contains("participle of") || - name.contains("gerund of") || - name.contains("feminine of") || - name.contains("plural of")) { - functionCallback = functionCallbacks.get("form of"); - } - } if (functionCallback == null || !functionCallback.onWikiFunction(wikiTokenizer, name, args, namedArgs, parser, this)) { // Default function handling: namedArgs.keySet().removeAll(EnWiktionaryXmlParser.USELESS_WIKI_ARGS); @@ -122,6 +129,12 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback { } } + @Override + public void onHtml(WikiTokenizer wikiTokenizer) { + // Unindexed for now. + builder.append(wikiTokenizer.token()); + } + @Override public void onMarkup(WikiTokenizer wikiTokenizer) { // Do nothing.