Skip to content

Commit a654241

Browse files
committed
Get 'isChanged' directly from the SsurgeonPattern, rather than trying to compare the graphs, which is problematic in the case of EditNode or something else that changes information which isn't compared by SemanticGraph.equals()
1 parent b8bcecd commit a654241

File tree

3 files changed

+73
-67
lines changed

3 files changed

+73
-67
lines changed

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/ProcessSsurgeonRequest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer;
1919
import edu.stanford.nlp.pipeline.CoreNLPProtos;
2020
import edu.stanford.nlp.semgraph.SemanticGraph;
21+
import edu.stanford.nlp.util.Pair;
2122
import edu.stanford.nlp.util.ProcessProtobufRequest;
2223
import edu.stanford.nlp.util.XMLUtils;
2324

@@ -61,10 +62,12 @@ public static CoreNLPProtos.SsurgeonResponse processRequest(CoreNLPProtos.Ssurge
6162
CoreNLPProtos.SsurgeonResponse.Builder responseBuilder = CoreNLPProtos.SsurgeonResponse.newBuilder();
6263
for (SemanticGraph graph : graphs) {
6364
SemanticGraph newGraph = graph;
65+
boolean isChanged = false;
6466
for (SsurgeonPattern pattern : patterns) {
65-
newGraph = pattern.iterate(newGraph);
67+
Pair<SemanticGraph, Boolean> result = pattern.iterate(newGraph);
68+
newGraph = result.first;
69+
isChanged = isChanged || result.second;
6670
}
67-
boolean isChanged = !graph.equals(newGraph);
6871
CoreNLPProtos.SsurgeonResponse.SsurgeonResult.Builder graphBuilder = CoreNLPProtos.SsurgeonResponse.SsurgeonResult.newBuilder();
6972
graphBuilder.setGraph(serializer.toProto(newGraph, true));
7073
graphBuilder.setChanged(isChanged);

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SsurgeonPattern.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import edu.stanford.nlp.semgraph.semgrex.ssurgeon.pred.SsurgPred;
1111
import edu.stanford.nlp.semgraph.semgrex.*;
1212
import edu.stanford.nlp.util.Generics;
13+
import edu.stanford.nlp.util.Pair;
1314

1415
/**
1516
* This represents a source pattern and a subsequent edit script, or a sequence
@@ -181,10 +182,11 @@ public Collection<SemanticGraph> execute(SemanticGraph sg) {
181182
* and update the SemgrexMatcher when inserting new nodes.
182183
* </ul>
183184
*/
184-
public SemanticGraph iterate(SemanticGraph sg) {
185+
public Pair<SemanticGraph, Boolean> iterate(SemanticGraph sg) {
185186
SemanticGraph copied = new SemanticGraph(sg);
186187

187188
SemgrexMatcher matcher = semgrexPattern.matcher(copied);
189+
boolean anyChanges = false;
188190
while (matcher.find()) {
189191
// We reset the named node map with each edit set, since these edits
190192
// should exist in a separate graph for each unique Semgrex match.
@@ -193,13 +195,14 @@ public SemanticGraph iterate(SemanticGraph sg) {
193195
for (SsurgeonEdit edit : editScript) {
194196
if (edit.evaluate(copied, matcher)) {
195197
edited = true;
198+
anyChanges = true;
196199
}
197200
}
198201
if (edited) {
199202
matcher = semgrexPattern.matcher(copied);
200203
}
201204
}
202-
return copied;
205+
return new Pair<>(copied, anyChanges);
203206
}
204207

205208
/**

0 commit comments

Comments
 (0)