Skip to content

Commit 2db3e6a

Browse files
committed
Use the incoming edge iterator instead of the parent nodes. A bit cleaner, and a later change to keep the matched edge will be much easier to write
1 parent 62fb8f5 commit 2db3e6a

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/edu/stanford/nlp/semgraph/semgrex/GraphRelation.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -308,31 +308,27 @@ boolean satisfies(IndexedWord l1, IndexedWord l2, SemanticGraph sg) {
308308
@Override
309309
Iterator<IndexedWord> searchNodeIterator(final IndexedWord node, final SemanticGraph sg) {
310310
return new SearchNodeIterator() {
311-
int nextNum; // subtle bug warning here: if we use int nextNum=0;
312-
313-
// instead,
314-
315-
// we get the first daughter twice because the assignment occurs after
316-
// advance() has already been
317-
// called once by the constructor of SearchNodeIterator.
311+
Iterator<SemanticGraphEdge> iterator;
318312

319313
@Override
320314
public void advance() {
321315
if (node.equals(IndexedWord.NO_WORD)) {
322316
next = null;
323317
return;
324318
}
325-
List<Pair<GrammaticalRelation, IndexedWord>> govs = sg.parentPairs(node);
326-
while (nextNum < govs.size() && !type.test(govs.get(nextNum).first().toString())) {
327-
nextNum++;
319+
if (iterator == null) {
320+
iterator = sg.incomingEdgeIterator(node);
328321
}
329-
if (nextNum < govs.size()) {
330-
next = govs.get(nextNum).second();
331-
relation = govs.get(nextNum).first().toString();
332-
nextNum++;
333-
} else {
334-
next = null;
322+
while (iterator.hasNext()) {
323+
SemanticGraphEdge edge = iterator.next();
324+
relation = edge.getRelation().toString();
325+
if (!type.test(relation)) {
326+
continue;
327+
}
328+
this.next = edge.getSource();
329+
return;
335330
}
331+
this.next = null;
336332
}
337333
};
338334
}

0 commit comments

Comments
 (0)