]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/engine/IndexBuilder.java
Added Urdu!
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / IndexBuilder.java
index 9e6b6c09378bdc222739567de949ceaf83b5def5..1140b64ac7579a8067937095c9331949d99f8e8e 100644 (file)
@@ -46,11 +46,17 @@ public class IndexBuilder {
   public void build() {
     final Set<IndexedEntry> tokenEntryDatas = new HashSet<IndexedEntry>();
     final List<RowBase> rows = index.rows;
+    index.mainTokenCount = 0;
     for (final TokenData tokenData : tokenToData.values()) {
       tokenEntryDatas.clear();
       final int indexIndex = index.sortedIndexEntries.size();
       final int startRow = rows.size();
-      rows.add(new TokenRow(indexIndex, rows.size(), index));
+      
+      final TokenRow tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+      rows.add(tokenRow);
+      if (tokenRow.hasMainEntry) {
+        index.mainTokenCount++;
+      }
 //      System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
       int numRows = 0;
 //      System.out.println("TOKEN: " + tokenData.token);
@@ -62,6 +68,7 @@ public class IndexBuilder {
           }
           if (tokenEntryDatas.add(entryData)) {
             rows.add(new PairEntry.Row(entryData.index(), rows.size(), index));
+            ++entryData.entry.entrySource.numEntries;
             ++numRows;
             
 //            System.out.print("  " + typeToEntry.getKey() + ": ");
@@ -74,15 +81,15 @@ public class IndexBuilder {
           .normalizer().transliterate(tokenData.token), startRow, numRows));
     }
     
-    final List<IndexEntry> entriesSortedByRows = new ArrayList<IndexEntry>(index.sortedIndexEntries);
-    Collections.sort(entriesSortedByRows, new Comparator<IndexEntry>() {
+    final List<IndexEntry> entriesSortedByNumRows = new ArrayList<IndexEntry>(index.sortedIndexEntries);
+    Collections.sort(entriesSortedByNumRows, 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 < entriesSortedByRows.size(); ++i) {
-      System.out.println("  " + entriesSortedByRows.get(i));
+    for (int i = 0; i < 50 && i < entriesSortedByNumRows.size(); ++i) {
+      System.out.println("  " + entriesSortedByNumRows.get(i));
     }
   }
   
@@ -90,6 +97,7 @@ public class IndexBuilder {
     final String token;
         
     final Map<EntryTypeName, List<IndexedEntry>> typeToEntries = new EnumMap<EntryTypeName, List<IndexedEntry>>(EntryTypeName.class);
+    boolean hasMainEntry = false;
     
     TokenData(final String token) {
       assert token.equals(token.trim());
@@ -110,6 +118,9 @@ public class IndexBuilder {
   private List<IndexedEntry> getOrCreateEntries(final String token, final EntryTypeName entryTypeName) {
     final TokenData tokenData = getOrCreateTokenData(token);
     List<IndexedEntry> entries = tokenData.typeToEntries.get(entryTypeName);
+    if (entryTypeName.overridesStopList) {
+      tokenData.hasMainEntry = true;
+    }
     if (entries == null) {
       entries = new ArrayList<IndexedEntry>();
       tokenData.typeToEntries.put(entryTypeName, entries);
@@ -119,20 +130,26 @@ public class IndexBuilder {
 
   public void addEntryWithTokens(final IndexedEntry indexedEntry, final Set<String> tokens,
       final EntryTypeName entryTypeName) {
+    if (indexedEntry == null) {
+      System.out.println("asdfasdf");
+    }
+    assert indexedEntry != null;
     for (final String token : tokens) {
-      if (entryTypeName.overridesStopList || !stoplist.contains(token))
-      getOrCreateEntries(token, entryTypeName).add(indexedEntry);
+      if (entryTypeName.overridesStopList || !stoplist.contains(token)) {
+        getOrCreateEntries(token, entryTypeName).add(indexedEntry);
+      }
     }    
   }
 
   public void addEntryWithString(final IndexedEntry indexedEntry, final String untokenizedString,
-      final EntryTypeName singleTokenEntryTypeName, final EntryTypeName multiTokenEntryTypeName) {
+      final EntryTypeName entryTypeName) {
     final Set<String> tokens = DictFileParser.tokenize(untokenizedString, DictFileParser.NON_CHAR);
-    addEntryWithTokens(indexedEntry, tokens, tokens.size() == 1 ? singleTokenEntryTypeName : multiTokenEntryTypeName);
+    addEntryWithTokens(indexedEntry, tokens, tokens.size() == 1 ? entryTypeName.singleWordInstance : entryTypeName);
   }
 
-  public void addEntryWithString(final IndexedEntry indexedEntry, final String untokenizedString,
+  public void addEntryWithStringNoSingle(final IndexedEntry indexedEntry, final String untokenizedString,
       final EntryTypeName entryTypeName) {
-    addEntryWithString(indexedEntry, untokenizedString, entryTypeName, entryTypeName);
+    final Set<String> tokens = DictFileParser.tokenize(untokenizedString, DictFileParser.NON_CHAR);
+    addEntryWithTokens(indexedEntry, tokens, entryTypeName);
   }
 }