-
- final DictionaryBuilder dictionaryBuilder;
- final Index index;
-
- final SortedMap<String, TokenData> tokenToData;
-
- @SuppressWarnings("unchecked")
- IndexBuilder(final DictionaryBuilder dictionaryBuilder, final String shortName, final String longName, final Language language) {
- this.dictionaryBuilder = dictionaryBuilder;
- index = new Index(dictionaryBuilder.dictionary, shortName, longName, language);
- tokenToData = new TreeMap<String, TokenData>(language.getSortCollator());
- }
-
- public void build() {
- final Set<EntryData> tokenEntryDatas = new HashSet<EntryData>();
- 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);
- 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;
-
- System.out.print(" " + typeToEntry.getKey() + ": ");
- rows.get(rows.size() - 1).print(System.out);
- System.out.println();
- }
+
+ final DictionaryBuilder dictionaryBuilder;
+ public final Index index;
+ final Set<String> stoplist;
+
+ final SortedMap<FastCompareString, TokenData> tokenToData;
+
+ IndexBuilder(final DictionaryBuilder dictionaryBuilder, final String shortName, final String longName, final Language language, final String normalizerRules, final Set<String> stoplist, final boolean swapPairEntries) {
+ this.dictionaryBuilder = dictionaryBuilder;
+ index = new Index(dictionaryBuilder.dictionary, shortName, longName, language, normalizerRules, swapPairEntries, stoplist);
+ tokenToData = new TreeMap<>(new FastNormalizeComparator(index.getSortComparator()));
+ this.stoplist = stoplist;
+ }
+
+ public void build() {
+ final Set<IndexedEntry> tokenIndexedEntries = new HashSet<>();
+ final List<RowBase> rows = index.rows;
+ index.mainTokenCount = 0;
+ for (final TokenData tokenData : tokenToData.values()) {
+ tokenIndexedEntries.clear();
+ final int indexIndex = index.sortedIndexEntries.size();
+ final int startRow = rows.size();
+
+ TokenRow tokenRow = null;
+ if (!tokenData.htmlEntries.isEmpty()) {
+ tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+ rows.add(tokenRow);
+ }
+
+// System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
+
+ int numRows = 0; // off by one--doesn't count the token row!
+// System.out.println("TOKEN: " + tokenData.token);
+ for (final Map.Entry<EntryTypeName, List<IndexedEntry>> typeToIndexedEntries : tokenData.typeToEntries.entrySet()) {
+ for (final IndexedEntry indexedEntry : typeToIndexedEntries.getValue()) {
+ if (!indexedEntry.isValid) {
+ continue;
+ }
+
+ if (tokenRow == null) {
+ tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+ rows.add(tokenRow);
+ }
+
+ if (indexedEntry.entry.index() == -1) {
+ indexedEntry.entry.addToDictionary(dictionaryBuilder.dictionary);
+ assert indexedEntry.entry.index() >= 0;
+ }
+ if (tokenIndexedEntries.add(indexedEntry) && !tokenData.htmlEntries.contains(indexedEntry.entry)) {
+ rows.add(indexedEntry.entry.CreateRow(rows.size(), index));
+ ++indexedEntry.entry.entrySource.numEntries;
+ ++numRows;
+
+// System.out.print(" " + typeToEntry.getKey() + ": ");
+ // rows.get(rows.size() - 1).print(System.out);
+// System.out.println();
+ }
+ }
+ }
+
+ if (tokenRow != null) {
+ if (tokenRow.hasMainEntry) {
+ index.mainTokenCount++;
+ }
+
+ final Index.IndexEntry indexEntry = new Index.IndexEntry(index, tokenData.token, index
+ .normalizer().transliterate(tokenData.token), startRow, numRows);
+ indexEntry.htmlEntries.addAll(tokenData.htmlEntries);
+ index.sortedIndexEntries.add(indexEntry);
+ }
+ }
+
+ final List<IndexEntry> entriesSortedByNumRows = new ArrayList<>(index.sortedIndexEntries);
+ entriesSortedByNumRows.sort((object1, object2) -> object2.numRows - object1.numRows);
+ System.out.println("Most common tokens:");
+ for (int i = 0; i < 50 && i < entriesSortedByNumRows.size(); ++i) {
+ System.out.println(" " + entriesSortedByNumRows.get(i));