File tree Expand file tree Collapse file tree 3 files changed +73
-67
lines changed
src/edu/stanford/nlp/semgraph/semgrex/ssurgeon
test/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon Expand file tree Collapse file tree 3 files changed +73
-67
lines changed Original file line number Diff line number Diff line change 1818import edu .stanford .nlp .pipeline .ProtobufAnnotationSerializer ;
1919import edu .stanford .nlp .pipeline .CoreNLPProtos ;
2020import edu .stanford .nlp .semgraph .SemanticGraph ;
21+ import edu .stanford .nlp .util .Pair ;
2122import edu .stanford .nlp .util .ProcessProtobufRequest ;
2223import 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 );
Original file line number Diff line number Diff line change 1010import edu .stanford .nlp .semgraph .semgrex .ssurgeon .pred .SsurgPred ;
1111import edu .stanford .nlp .semgraph .semgrex .*;
1212import 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 /**
You can’t perform that action at this time.
0 commit comments