Skip to content

Commit

Permalink
rm dicId arg from lexicon.wordIds
Browse files Browse the repository at this point in the history
  • Loading branch information
mh-northlander committed Nov 27, 2024
1 parent 32920ec commit d6a65d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,16 @@ public int size() {
return description.getNumTotalEntries();
}

public Iterator<Integer> wordIds(int dic) {
return new WordIdItr(dic);
public Iterator<Integer> wordIds() {
return new WordIdItr();
}

private class WordIdItr implements Iterator<Integer> {
int dictId;
Iterator<Ints> iterator;
Ints ints;
int index;

WordIdItr(int dic) {
dictId = dic;
WordIdItr() {
this.iterator = getWordIdTable().wordIds();
index = 0;
}
Expand All @@ -183,8 +181,7 @@ public Integer next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
int rawWordId = ints.get(index++);
return WordId.make(dictId, rawWordId);
return ints.get(index++);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/worksap/nlp/sudachi/dictionary/Lexicon.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ public interface Lexicon {
WordInfoList wordInfos(int dic);

/**
* Iterates over all word ids in the specified dictionary.
* Iterates over all word ids in the dictionary.
*
* Returned word ids are not sorted. Dictionary part of returned ids are filled
* by the given dicId.
* Returned word ids are not sorted.
*/
Iterator<Integer> wordIds(int dic);
Iterator<Integer> wordIds();
}
17 changes: 4 additions & 13 deletions src/main/java/com/worksap/nlp/sudachi/dictionary/LexiconSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,6 @@ public WordInfoList wordInfos(int dic) {
}

@Override
public Iterator<Integer> wordIds(int dic) {
return lexicons.get(dic).wordIds(dic);
}

/**
* Iterates over all word ids in all lexicons.
*
* Returned word ids are not sorted. Dictionary part of returned ids are filled
* by the proper dict-ids.
*/
public Iterator<Integer> wordIds() {
return new WordIdItr();
}
Expand All @@ -191,7 +181,7 @@ private class WordIdItr implements Iterator<Integer> {

WordIdItr() {
this.dictId = 0;
this.iterator = wordIds(this.dictId);
this.iterator = lexicons.get(dictId).wordIds();
}

@Override
Expand All @@ -202,7 +192,7 @@ public boolean hasNext() {
return false;
}
dictId = nextDictId;
iterator = wordIds(nextDictId);
iterator = lexicons.get(nextDictId).wordIds();
}
return true;
}
Expand All @@ -212,7 +202,8 @@ public Integer next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return iterator.next();
int innerWordId = iterator.next();
return WordId.make(dictId, innerWordId);
}
}
}

0 comments on commit d6a65d9

Please sign in to comment.