@@ -178,6 +178,91 @@ public void readXMLRemoveNamedEdgeIterate() {
178
178
assertEquals (newSg , expected );
179
179
}
180
180
181
+ /**
182
+ * Test a few various relabel edge operations
183
+ */
184
+ @ Test
185
+ public void readXMLRelabelEdgeIterate () {
186
+ String doc = String .join (newline ,
187
+ "<ssurgeon-pattern-list>" ,
188
+ " <ssurgeon-pattern>" ,
189
+ " <uid>38</uid>" ,
190
+ " <notes>This is a simple test of RelabelNamedEdge</notes>" ,
191
+ " <semgrex>" + XMLUtils .escapeXML ("{}=a1 >obj=foo {}=a2" ) + "</semgrex>" ,
192
+ " <edit-list>relabelNamedEdge -edge foo -reln dep</edit-list>" ,
193
+ " </ssurgeon-pattern>" ,
194
+ "</ssurgeon-pattern-list>" );
195
+ Ssurgeon inst = Ssurgeon .inst ();
196
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
197
+ assertEquals (patterns .size (), 1 );
198
+ SsurgeonPattern pattern = patterns .get (0 );
199
+
200
+ // check a simple case of relabeling
201
+ SemanticGraph sg = SemanticGraph .valueOf ("[A-0 obj> B-1]" );
202
+ SemanticGraph expected = SemanticGraph .valueOf ("[A-0 dep> B-1]" );
203
+ SemanticGraph newSg = pattern .iterate (sg );
204
+ assertEquals (newSg , expected );
205
+
206
+ // check iteration over multiple edges
207
+ sg = SemanticGraph .valueOf ("[A-0 obj> [B-1 obj> C-2]]" );
208
+ expected = SemanticGraph .valueOf ("[A-0 dep> [B-1 dep> C-2]]" );
209
+ newSg = pattern .iterate (sg );
210
+ assertEquals (newSg , expected );
211
+
212
+ // check that relabeling doesn't change a non-matching edge
213
+ // (how would it?)
214
+ sg = SemanticGraph .valueOf ("[A-0 iobj> B-1]" );
215
+ expected = SemanticGraph .valueOf ("[A-0 iobj> B-1]" );
216
+ newSg = pattern .iterate (sg );
217
+ assertEquals (newSg , expected );
218
+
219
+ // check that you don't get double edges if an update
220
+ // makes two edges into the same edge
221
+ sg = SemanticGraph .valueOf ("[A-0 obj> B-1 dep> B-1]" );
222
+ expected = SemanticGraph .valueOf ("[A-0 dep> B-1]" );
223
+ newSg = pattern .iterate (sg );
224
+ assertEquals (newSg , expected );
225
+ }
226
+
227
+
228
+ /**
229
+ * Test that the RelabelNamedEdge operation updates the name of the edge in the SemgrexMatcher
230
+ */
231
+ @ Test
232
+ public void readXMLRelabelEdgeUpdateNamedEdge () {
233
+ String doc = String .join (newline ,
234
+ "<ssurgeon-pattern-list>" ,
235
+ " <ssurgeon-pattern>" ,
236
+ " <uid>38</uid>" ,
237
+ " <notes>This is a simple test of RelabelNamedEdge</notes>" ,
238
+ " <semgrex>" + XMLUtils .escapeXML ("{}=a1 >obj=foo {}=a2" ) + "</semgrex>" ,
239
+ " <edit-list>relabelNamedEdge -edge foo -reln dep</edit-list>" ,
240
+ " <edit-list>relabelNamedEdge -edge foo -reln gov</edit-list>" ,
241
+ " </ssurgeon-pattern>" ,
242
+ "</ssurgeon-pattern-list>" );
243
+ Ssurgeon inst = Ssurgeon .inst ();
244
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
245
+ assertEquals (patterns .size (), 1 );
246
+ SsurgeonPattern pattern = patterns .get (0 );
247
+
248
+ // check the result of a double relabel - should wind up as gov
249
+ SemanticGraph sg = SemanticGraph .valueOf ("[A-0 obj> B-1]" );
250
+ SemanticGraph expected = SemanticGraph .valueOf ("[A-0 gov> B-1]" );
251
+ SemanticGraph newSg = pattern .iterate (sg );
252
+ assertEquals (newSg , expected );
253
+
254
+ // in this case, the dep should acquire the name of the obj
255
+ // in the SemgrexMatcher. the subsequent operation will pick up
256
+ // that edge (with the original edge being deleted) and the
257
+ // result will be one edge with the name "gov"
258
+ // if the matcher did not update the named edge as expected,
259
+ // the second operation would not fire
260
+ sg = SemanticGraph .valueOf ("[A-0 obj> B-1 dep> B-1]" );
261
+ expected = SemanticGraph .valueOf ("[A-0 gov> B-1]" );
262
+ newSg = pattern .iterate (sg );
263
+ assertEquals (newSg , expected );
264
+ }
265
+
181
266
/**
182
267
* Check that cutting a graph with two nodes into two pieces, then
183
268
* pruning any disjoint pieces, results in a graph with just the root
0 commit comments