@@ -117,6 +117,40 @@ public void readXMLRemoveEdgeIterate() {
117
117
assertEquals (newSg , expected );
118
118
}
119
119
120
+
121
+ /**
122
+ * Test that removing a named edge will remove all matching edges
123
+ */
124
+ @ Test
125
+ public void readXMLRemoveNamedEdgeIterate () {
126
+ String doc = String .join (newline ,
127
+ "<ssurgeon-pattern-list>" ,
128
+ " <ssurgeon-pattern>" ,
129
+ " <uid>38</uid>" ,
130
+ " <notes>This is a simple test of RemoveNamedEdge</notes>" ,
131
+ " <semgrex>" + XMLUtils .escapeXML ("{}=a1 >dep~foo {}=a2" ) + "</semgrex>" ,
132
+ " <edit-list>removeNamedEdge -edge foo</edit-list>" ,
133
+ " </ssurgeon-pattern>" ,
134
+ "</ssurgeon-pattern-list>" );
135
+ Ssurgeon inst = Ssurgeon .inst ();
136
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
137
+ assertEquals (patterns .size (), 1 );
138
+ SsurgeonPattern pattern = patterns .get (0 );
139
+
140
+ SemanticGraph sg = SemanticGraph .valueOf ("[A-0 obj> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]" );
141
+ SemanticGraph newSg = pattern .iterate (sg );
142
+ SemanticGraph expected = SemanticGraph .valueOf ("[A-0 obj> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]" );
143
+ assertEquals (newSg , sg );
144
+
145
+ sg = SemanticGraph .valueOf ("[A-0 obj> B-1 dep> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]" );
146
+ newSg = pattern .iterate (sg );
147
+ assertEquals (newSg , expected );
148
+
149
+ sg = SemanticGraph .valueOf ("[A-0 obj> B-1 dep> B-1 obj> C-2 dep> C-2 nsubj> [D-3 obj> E-4 dep> E-4]]" );
150
+ newSg = pattern .iterate (sg );
151
+ assertEquals (newSg , expected );
152
+ }
153
+
120
154
/**
121
155
* Check that cutting a graph with two nodes into two pieces, then
122
156
* pruning any disjoint pieces, results in a graph with just the root
@@ -241,16 +275,16 @@ public void readXMLPruneNodesResetRoots() {
241
275
@ Test
242
276
public void simpleTest () {
243
277
SemanticGraph sg = SemanticGraph .valueOf ("[mixed/VBN nsubj>[Joe/NNP appos>[bartender/NN det>the/DT]] obj>[drink/NN det>a/DT]]" );
244
- SemgrexPattern semgrexPattern = SemgrexPattern .compile ("{}=a1 >appos= e1 {}=a2 <nsubj= e2 {}=a3" );
278
+ SemgrexPattern semgrexPattern = SemgrexPattern .compile ("{}=a1 >appos~ e1 {}=a2 <nsubj~ e2 {}=a3" );
245
279
SsurgeonPattern pattern = new SsurgeonPattern (semgrexPattern );
246
280
247
281
System .out .println ("Start = " +sg .toCompactString ());
248
282
249
283
// Find and snip the appos and root to nsubj links
250
- SsurgeonEdit apposSnip = new RemoveNamedEdge ("e1" , "a1" , "a2" );
284
+ SsurgeonEdit apposSnip = new RemoveNamedEdge ("e1" );
251
285
pattern .addEdit (apposSnip );
252
286
253
- SsurgeonEdit nsubjSnip = new RemoveNamedEdge ("e2" , "a3" , "a1" );
287
+ SsurgeonEdit nsubjSnip = new RemoveNamedEdge ("e2" );
254
288
pattern .addEdit (nsubjSnip );
255
289
256
290
// Attach Joe to be the nsubj of bartender
0 commit comments