@@ -752,7 +752,7 @@ public void readXMLAddDepRelativePosition() {
752
752
* Check that adding a word using the attributes of the edit-list works as expected
753
753
*/
754
754
@ Test
755
- public void readXMLAddDepAttributes () {
755
+ public void readXMLAddDepNodeAttributes () {
756
756
Ssurgeon inst = Ssurgeon .inst ();
757
757
758
758
// use "dep" as the dependency so as to be language-agnostic in this test
@@ -843,6 +843,72 @@ public void readXMLAddDepAttributes() {
843
843
}
844
844
845
845
846
+ /**
847
+ * Check that adding a word using quotes for the attributes
848
+ */
849
+ @ Test
850
+ public void readXMLAddDepQuotedAttributes () {
851
+ Ssurgeon inst = Ssurgeon .inst ();
852
+
853
+ // use "dep" as the dependency so as to be language-agnostic in this test
854
+ String add = String .join (newline ,
855
+ "<ssurgeon-pattern-list>" ,
856
+ " <ssurgeon-pattern>" ,
857
+ " <uid>38</uid>" ,
858
+ " <notes>Add a word using the attributes of the edit-list node</notes>" ,
859
+ // have to bomb-proof the pattern
860
+ " <semgrex>" + XMLUtils .escapeXML ("{word:antennae}=antennae !> {word:blue}" ) + "</semgrex>" ,
861
+ " <edit-list>addDep -gov antennae -reln \" dep\" -word \" blue\" -position -antennae</edit-list>" ,
862
+ " </ssurgeon-pattern>" ,
863
+ "</ssurgeon-pattern-list>" );
864
+ List <SsurgeonPattern > patterns = inst .readFromString (add );
865
+ assertEquals (patterns .size (), 1 );
866
+ SsurgeonPattern addSsurgeon = patterns .get (0 );
867
+
868
+ SemanticGraph sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> antennae-3]" );
869
+ IndexedWord blueVertex = sg .getNodeByIndexSafe (4 );
870
+ assertNull (blueVertex );
871
+ SemanticGraph newSG = addSsurgeon .iterate (sg );
872
+ SemanticGraph expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
873
+ assertEquals (expected , newSG );
874
+ // the Ssurgeon we just created should not put a tag on the word
875
+ // but it SHOULD put blue immediately before antennae
876
+ blueVertex = newSG .getNodeByIndexSafe (3 );
877
+ assertNotNull (blueVertex );
878
+ assertNull (blueVertex .tag ());
879
+ assertEquals ("blue" , blueVertex .value ());
880
+
881
+ // use "dep" as the dependency so as to be language-agnostic in this test
882
+ // this time, be cheeky and use some whitespace in the word
883
+ add = String .join (newline ,
884
+ "<ssurgeon-pattern-list>" ,
885
+ " <ssurgeon-pattern>" ,
886
+ " <uid>38</uid>" ,
887
+ " <notes>Add a word using the attributes of the edit-list node</notes>" ,
888
+ // have to bomb-proof the pattern
889
+ " <semgrex>" + XMLUtils .escapeXML ("{word:antennae}=antennae !> {word:/bl ue/}" ) + "</semgrex>" ,
890
+ " <edit-list>addDep -gov antennae -reln \" dep\" -word \" bl ue\" -position -antennae</edit-list>" ,
891
+ " </ssurgeon-pattern>" ,
892
+ "</ssurgeon-pattern-list>" );
893
+ patterns = inst .readFromString (add );
894
+ assertEquals (patterns .size (), 1 );
895
+ addSsurgeon = patterns .get (0 );
896
+
897
+ sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> antennae-3]" );
898
+ blueVertex = sg .getNodeByIndexSafe (4 );
899
+ assertNull (blueVertex );
900
+ newSG = addSsurgeon .iterate (sg );
901
+ expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
902
+ assertEquals (expected , newSG );
903
+ // the Ssurgeon we just created should not put a tag on the word
904
+ // but it SHOULD put blue immediately before antennae
905
+ blueVertex = newSG .getNodeByIndexSafe (3 );
906
+ assertNotNull (blueVertex );
907
+ assertNull (blueVertex .tag ());
908
+ assertEquals ("bl ue" , blueVertex .value ());
909
+ }
910
+
911
+
846
912
/**
847
913
* Add a word, this time setting the morphological features as well
848
914
*/
0 commit comments