@@ -117,6 +117,40 @@ public void readXMLRemoveEdgeIterate() {
117117 assertEquals (newSg , expected );
118118 }
119119
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+
120154 /**
121155 * Check that cutting a graph with two nodes into two pieces, then
122156 * pruning any disjoint pieces, results in a graph with just the root
@@ -241,16 +275,16 @@ public void readXMLPruneNodesResetRoots() {
241275 @ Test
242276 public void simpleTest () {
243277 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" );
245279 SsurgeonPattern pattern = new SsurgeonPattern (semgrexPattern );
246280
247281 System .out .println ("Start = " +sg .toCompactString ());
248282
249283 // Find and snip the appos and root to nsubj links
250- SsurgeonEdit apposSnip = new RemoveNamedEdge ("e1" , "a1" , "a2" );
284+ SsurgeonEdit apposSnip = new RemoveNamedEdge ("e1" );
251285 pattern .addEdit (apposSnip );
252286
253- SsurgeonEdit nsubjSnip = new RemoveNamedEdge ("e2" , "a3" , "a1" );
287+ SsurgeonEdit nsubjSnip = new RemoveNamedEdge ("e2" );
254288 pattern .addEdit (nsubjSnip );
255289
256290 // Attach Joe to be the nsubj of bartender
0 commit comments