@@ -683,6 +683,70 @@ public void readXMLAddDepStartPosition() {
683
683
assertEquals ("blue" , blueVertex .value ());
684
684
}
685
685
686
+ /**
687
+ * Check that adding a word before or after a named node works as expected
688
+ */
689
+ @ Test
690
+ public void readXMLAddDepRelativePosition () {
691
+ Ssurgeon inst = Ssurgeon .inst ();
692
+
693
+ // use "dep" as the dependency so as to be language-agnostic in this test
694
+ String add = String .join (newline ,
695
+ "<ssurgeon-pattern-list>" ,
696
+ " <ssurgeon-pattern>" ,
697
+ " <uid>38</uid>" ,
698
+ " <notes>Add a word before antennae using the position</notes>" ,
699
+ // have to bomb-proof the pattern
700
+ " <semgrex>" + XMLUtils .escapeXML ("{word:antennae}=antennae !> {word:blue}" ) + "</semgrex>" ,
701
+ " <edit-list>addDep -gov antennae -reln dep -word blue -position -antennae</edit-list>" ,
702
+ " </ssurgeon-pattern>" ,
703
+ "</ssurgeon-pattern-list>" );
704
+ List <SsurgeonPattern > patterns = inst .readFromString (add );
705
+ assertEquals (patterns .size (), 1 );
706
+ SsurgeonPattern addSsurgeon = patterns .get (0 );
707
+
708
+ SemanticGraph sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> antennae-3]" );
709
+ IndexedWord blueVertex = sg .getNodeByIndexSafe (4 );
710
+ assertNull (blueVertex );
711
+ SemanticGraph newSG = addSsurgeon .iterate (sg );
712
+ SemanticGraph expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
713
+ assertEquals (expected , newSG );
714
+ // the Ssurgeon we just created should not put a tag on the word
715
+ // but it SHOULD put blue immediately before antennae
716
+ blueVertex = newSG .getNodeByIndexSafe (3 );
717
+ assertNotNull (blueVertex );
718
+ assertNull (blueVertex .tag ());
719
+ assertEquals ("blue" , blueVertex .value ());
720
+
721
+ // use "dep" as the dependency so as to be language-agnostic in this test
722
+ add = String .join (newline ,
723
+ "<ssurgeon-pattern-list>" ,
724
+ " <ssurgeon-pattern>" ,
725
+ " <uid>38</uid>" ,
726
+ " <notes>Add a word after the word before antennae (just to test the position)</notes>" ,
727
+ // have to bomb-proof the pattern
728
+ " <semgrex>" + XMLUtils .escapeXML ("{word:antennae}=antennae - {}=prev !> {word:blue}" ) + "</semgrex>" ,
729
+ " <edit-list>addDep -gov antennae -reln dep -word blue -position +prev</edit-list>" ,
730
+ " </ssurgeon-pattern>" ,
731
+ "</ssurgeon-pattern-list>" );
732
+ patterns = inst .readFromString (add );
733
+ assertEquals (patterns .size (), 1 );
734
+ addSsurgeon = patterns .get (0 );
735
+
736
+ sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> antennae-3]" );
737
+ blueVertex = sg .getNodeByIndexSafe (4 );
738
+ assertNull (blueVertex );
739
+ newSG = addSsurgeon .iterate (sg );
740
+ expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
741
+ assertEquals (expected , newSG );
742
+ // the Ssurgeon we just created should not put a tag on the word
743
+ // but it SHOULD put blue immediately before antennae
744
+ blueVertex = newSG .getNodeByIndexSafe (3 );
745
+ assertNotNull (blueVertex );
746
+ assertNull (blueVertex .tag ());
747
+ assertEquals ("blue" , blueVertex .value ());
748
+ }
749
+
686
750
/**
687
751
* There should be an exception for an annotation key that does not exist
688
752
*/
0 commit comments