Skip to content

Commit

Permalink
use public api to get word id list
Browse files Browse the repository at this point in the history
  • Loading branch information
mh-northlander committed Dec 2, 2024
1 parent 5d57e7d commit d458f88
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DictionaryPrinter {
private final LexiconSet lex;
private final TextNormalizer textNormalizer;
// sorted raw word ids taken from the target dict.
private final Ints wordIds;
private final int[] wordIds;

private POSMode posMode = POSMode.DEFAULT;
private WordRefMode wordRefMode = WordRefMode.DEFAULT;
Expand Down Expand Up @@ -98,18 +98,15 @@ public enum WordRefMode {

// In order to output dictionary entries in in-dictionary order we need to sort
// them. Iterator over them will get them not in the sorted order, but grouped
// by index-form. Here we assume DoubleArrayLexicon and use WordIdTable.wordIds
// for the performance.
DoubleArrayLexicon targetLex = dic.getLexicon();
Ints allIds = new Ints(targetLex.size());
Iterator<Ints> ids = targetLex.getWordIdTable().wordIds();
// by index-form.
Lexicon targetLexicon = dic.getLexicon();
int[] allIds = new int[targetLexicon.size()];
int idx = 0;
Iterator<Integer> ids = targetLexicon.wordIds();
while (ids.hasNext()) {
allIds.appendAll(ids.next());
}
allIds.sort();
for (int i = 0; i < allIds.length(); i++) {
allIds.set(i, WordId.applyMask(allIds.get(i), dicIdMask));
allIds[idx++] = WordId.applyMask(ids.next(), dicIdMask);
}
Arrays.sort(allIds);
wordIds = allIds;
}

Expand Down Expand Up @@ -176,9 +173,9 @@ void printColumnHeaders(List<Column> headers) {

private void printEntries() {
progress.startBlock("Entries", System.nanoTime(), Progress.Kind.ENTRY);
long size = wordIds.length();
long size = wordIds.length;
for (int i = 0; i < size; ++i) {
printEntry(wordIds.get(i));
printEntry(wordIds[i]);
progress.progress(i, size);
}
progress.endBlock(size, System.nanoTime());
Expand Down

0 comments on commit d458f88

Please sign in to comment.