@@ -434,6 +434,68 @@ public void readXMLKillIncomingEdges() {
434
434
assertEquals (2 , cutSG .getRoots ().size ());
435
435
}
436
436
437
+ /**
438
+ * Check the result of rearranging an edge and then setting the root to a new label
439
+ */
440
+ @ Test
441
+ public void readXMLSetRoots () {
442
+ Ssurgeon inst = Ssurgeon .inst ();
443
+
444
+ String cut = String .join (newline ,
445
+ "<ssurgeon-pattern-list>" ,
446
+ " <ssurgeon-pattern>" ,
447
+ " <uid>38</uid>" ,
448
+ " <notes>Test the effects of setRoots on a simple change</notes>" ,
449
+ " <semgrex>" + XMLUtils .escapeXML ("{word:A}=a >dep=dep {word:B}=b" ) + "</semgrex>" ,
450
+ " <edit-list>removeNamedEdge -edge dep</edit-list>" ,
451
+ " <edit-list>addEdge -gov b -dep a -reln dep</edit-list>" ,
452
+ " <edit-list>setRoots b</edit-list>" ,
453
+ " </ssurgeon-pattern>" ,
454
+ "</ssurgeon-pattern-list>" );
455
+ List <SsurgeonPattern > patterns = inst .readFromString (cut );
456
+ assertEquals (patterns .size (), 1 );
457
+ SsurgeonPattern rearrange = patterns .get (0 );
458
+
459
+ // Test a two node only version
460
+ SemanticGraph sg = SemanticGraph .valueOf ("[A-1 dep> B-2]" );
461
+ SemanticGraph newSG = rearrange .iterate (sg );
462
+ SemanticGraph expected = SemanticGraph .valueOf ("[B-2 dep> A-1]" );
463
+ assertEquals (expected , newSG );
464
+ }
465
+
466
+
467
+ /**
468
+ * Check that a readable exception is thrown if the expected node doesn't exist for setRoots
469
+ */
470
+ @ Test
471
+ public void readXMLSetRootsException () {
472
+ Ssurgeon inst = Ssurgeon .inst ();
473
+
474
+ String cut = String .join (newline ,
475
+ "<ssurgeon-pattern-list>" ,
476
+ " <ssurgeon-pattern>" ,
477
+ " <uid>38</uid>" ,
478
+ " <notes>Remove all incoming edges for a node</notes>" ,
479
+ " <semgrex>" + XMLUtils .escapeXML ("{word:A}=a >dep~dep {word:B}=b" ) + "</semgrex>" ,
480
+ " <edit-list>removeNamedEdge -edge dep</edit-list>" ,
481
+ " <edit-list>addEdge -gov b -dep a -reln dep</edit-list>" ,
482
+ " <edit-list>setRoots c</edit-list>" ,
483
+ " </ssurgeon-pattern>" ,
484
+ "</ssurgeon-pattern-list>" );
485
+ List <SsurgeonPattern > patterns = inst .readFromString (cut );
486
+ assertEquals (patterns .size (), 1 );
487
+ SsurgeonPattern rearrange = patterns .get (0 );
488
+
489
+ // Test a two node only version
490
+ SemanticGraph sg = SemanticGraph .valueOf ("[A-1 dep> B-2]" );
491
+ try {
492
+ SemanticGraph newSG = rearrange .iterate (sg );
493
+ throw new AssertionError ("Expected a specific exception SsurgeonRuntimeException here" );
494
+ } catch (SsurgeonRuntimeException e ) {
495
+ // yay
496
+ }
497
+ }
498
+
437
499
/**
438
500
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
439
501
* a semgrex pattern, and then the resulting actions over the named nodes in the
0 commit comments