]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/engine/IndexBuilder.java
Moved around testdata.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / IndexBuilder.java
index 2db62905eb899342e22ba4f6eb84557c45b233ee..0e25e3388b6dbbed2070dd7f43325188a92e75f7 100644 (file)
@@ -1,6 +1,8 @@
 package com.hughes.android.dictionary.engine;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumMap;
 import java.util.HashSet;
 import java.util.List;
@@ -9,6 +11,8 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import com.hughes.android.dictionary.engine.Index.IndexEntry;
+
 
 public class IndexBuilder {
   
@@ -29,24 +33,36 @@ public class IndexBuilder {
     final List<RowBase> rows = index.rows;
     for (final TokenData tokenData : tokenToData.values()) {
       tokenEntryDatas.clear();
-      final int indexRow = index.sortedIndexEntries.size();
-      index.sortedIndexEntries.add(new Index.IndexEntry(tokenData.token, rows.size()));
-      rows.add(new TokenRow(indexRow, rows.size(), index));
-      System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
-      int count = 0;
-      System.out.println("TOKEN: " + tokenData.token);
+      final int indexIndex = index.sortedIndexEntries.size();
+      final int startRow = rows.size();
+      rows.add(new TokenRow(indexIndex, rows.size(), index));
+//      System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
+      int numRows = 0;
+//      System.out.println("TOKEN: " + tokenData.token);
       for (final Map.Entry<EntryTypeName, List<EntryData>> typeToEntry : tokenData.typeToEntries.entrySet()) {
         for (final EntryData entryData : typeToEntry.getValue()) {
           if (tokenEntryDatas.add(entryData)) {
             rows.add(new PairEntry.Row(entryData.index(), rows.size(), index));
-            ++count;
+            ++numRows;
             
-            System.out.print("  " + typeToEntry.getKey() + ": ");
-            rows.get(rows.size() - 1).print(System.out);
-            System.out.println();
+//            System.out.print("  " + typeToEntry.getKey() + ": ");
+  //          rows.get(rows.size() - 1).print(System.out);
+//            System.out.println();
           }
         }
       }
+      index.sortedIndexEntries.add(new Index.IndexEntry(tokenData.token, startRow, numRows));
+    }
+    
+    final List<IndexEntry> sortedEntries = new ArrayList<IndexEntry>(index.sortedIndexEntries);
+    Collections.sort(sortedEntries, new Comparator<IndexEntry>() {
+      @Override
+      public int compare(IndexEntry object1, IndexEntry object2) {
+        return object2.numRows - object1.numRows;
+      }});
+    System.out.println("Most common tokens:");
+    for (int i = 0; i < 50 && i < sortedEntries.size(); ++i) {
+      System.out.println("  " + sortedEntries.get(i));
     }
   }