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 18
18
import edu .stanford .nlp .pipeline .ProtobufAnnotationSerializer ;
19
19
import edu .stanford .nlp .pipeline .CoreNLPProtos ;
20
20
import edu .stanford .nlp .semgraph .SemanticGraph ;
21
+ import edu .stanford .nlp .util .Pair ;
21
22
import edu .stanford .nlp .util .ProcessProtobufRequest ;
22
23
import edu .stanford .nlp .util .XMLUtils ;
23
24
@@ -61,10 +62,12 @@ public static CoreNLPProtos.SsurgeonResponse processRequest(CoreNLPProtos.Ssurge
61
62
CoreNLPProtos .SsurgeonResponse .Builder responseBuilder = CoreNLPProtos .SsurgeonResponse .newBuilder ();
62
63
for (SemanticGraph graph : graphs ) {
63
64
SemanticGraph newGraph = graph ;
65
+ boolean isChanged = false ;
64
66
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 ;
66
70
}
67
- boolean isChanged = !graph .equals (newGraph );
68
71
CoreNLPProtos .SsurgeonResponse .SsurgeonResult .Builder graphBuilder = CoreNLPProtos .SsurgeonResponse .SsurgeonResult .newBuilder ();
69
72
graphBuilder .setGraph (serializer .toProto (newGraph , true ));
70
73
graphBuilder .setChanged (isChanged );
Original file line number Diff line number Diff line change 10
10
import edu .stanford .nlp .semgraph .semgrex .ssurgeon .pred .SsurgPred ;
11
11
import edu .stanford .nlp .semgraph .semgrex .*;
12
12
import edu .stanford .nlp .util .Generics ;
13
+ import edu .stanford .nlp .util .Pair ;
13
14
14
15
/**
15
16
* This represents a source pattern and a subsequent edit script, or a sequence
@@ -181,10 +182,11 @@ public Collection<SemanticGraph> execute(SemanticGraph sg) {
181
182
* and update the SemgrexMatcher when inserting new nodes.
182
183
* </ul>
183
184
*/
184
- public SemanticGraph iterate (SemanticGraph sg ) {
185
+ public Pair < SemanticGraph , Boolean > iterate (SemanticGraph sg ) {
185
186
SemanticGraph copied = new SemanticGraph (sg );
186
187
187
188
SemgrexMatcher matcher = semgrexPattern .matcher (copied );
189
+ boolean anyChanges = false ;
188
190
while (matcher .find ()) {
189
191
// We reset the named node map with each edit set, since these edits
190
192
// should exist in a separate graph for each unique Semgrex match.
@@ -193,13 +195,14 @@ public SemanticGraph iterate(SemanticGraph sg) {
193
195
for (SsurgeonEdit edit : editScript ) {
194
196
if (edit .evaluate (copied , matcher )) {
195
197
edited = true ;
198
+ anyChanges = true ;
196
199
}
197
200
}
198
201
if (edited ) {
199
202
matcher = semgrexPattern .matcher (copied );
200
203
}
201
204
}
202
- return copied ;
205
+ return new Pair <>( copied , anyChanges ) ;
203
206
}
204
207
205
208
/**
You can’t perform that action at this time.
0 commit comments