+// 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;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import com.hughes.android.dictionary.engine.EntryTypeName;
import com.hughes.android.dictionary.engine.IndexBuilder;
IndexBuilder indexBuilder;
final Map<String,FunctionCallback> functionCallbacks = new LinkedHashMap<String, FunctionCallback>();
+ boolean entryTypeNameSticks = false;
EntryTypeName entryTypeName = null;
+ final Map<String,AtomicInteger> langCodeToTCount = new LinkedHashMap<String, AtomicInteger>();
+
public AppendAndIndexWikiCallback(final EnWiktionaryXmlParser parser) {
this.parser = parser;
}
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;
public void onPlainText(final String plainText) {
// The only non-recursive callback. Just appends to the builder, and indexes.
builder.append(plainText);
- if (indexBuilder != null && entryTypeName != null) {
+ if (indexBuilder != null && entryTypeName != null && indexedEntry != null) {
indexBuilder.addEntryWithString(indexedEntry, plainText, entryTypeName);
}
}
final Map<String, String> namedArgs) {
FunctionCallback functionCallback = functionCallbacks.get(name);
- if (functionCallback == null) {
- if (
- name.equals("form of") ||
- 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);
}
}
+ @Override
+ public void onHtml(WikiTokenizer wikiTokenizer) {
+ // Unindexed for now.
+ builder.append(wikiTokenizer.token());
+ }
+
@Override
public void onMarkup(WikiTokenizer wikiTokenizer) {
// Do nothing.