]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/parser/enwiktionary/AppendAndIndexWikiCallback.java
zipSize, overrideStoplist-> special isMainEntry, tagalog, trying to
[DictionaryPC.git] / src / com / hughes / android / dictionary / parser / enwiktionary / AppendAndIndexWikiCallback.java
index 8e15fcea52d6b6785f716351be9bd27497a76352..c28b86c1d1bc0daf9bbd56bbb71e4f734e85176a 100644 (file)
@@ -1,8 +1,23 @@
+// 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;
@@ -18,8 +33,11 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback {
   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;
   }
@@ -29,13 +47,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;
@@ -51,7 +72,7 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback {
   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);
     }
   }
@@ -96,17 +117,6 @@ final class AppendAndIndexWikiCallback implements WikiTokenizer.Callback {
       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);
@@ -122,6 +132,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.