@@ -747,6 +747,49 @@ public void readXMLAddDepRelativePosition() {
747747 assertEquals ("blue" , blueVertex .value ());
748748 }
749749
750+
751+ /**
752+ * Add a word, this time setting the morphological features as well
753+ */
754+ @ Test
755+ public void readXMLAddDepMorphoFeatures () {
756+ Ssurgeon inst = Ssurgeon .inst ();
757+
758+ // use "dep" as the dependency so as to be language-agnostic in this test
759+ String add = String .join (newline ,
760+ "<ssurgeon-pattern-list>" ,
761+ " <ssurgeon-pattern>" ,
762+ " <uid>38</uid>" ,
763+ " <notes>Add a word before antennae using the position</notes>" ,
764+ // have to bomb-proof the pattern
765+ " <semgrex>" + XMLUtils .escapeXML ("{word:antennae}=antennae !> {word:blue}" ) + "</semgrex>" ,
766+ " <edit-list>addDep -gov antennae -reln dep -word blue -position -antennae -morphofeatures a=b|c=d</edit-list>" ,
767+ " </ssurgeon-pattern>" ,
768+ "</ssurgeon-pattern-list>" );
769+ List <SsurgeonPattern > patterns = inst .readFromString (add );
770+ assertEquals (patterns .size (), 1 );
771+ SsurgeonPattern addSsurgeon = patterns .get (0 );
772+
773+ SemanticGraph sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> antennae-3]" );
774+ IndexedWord blueVertex = sg .getNodeByIndexSafe (4 );
775+ assertNull (blueVertex );
776+ SemanticGraph newSG = addSsurgeon .iterate (sg );
777+ SemanticGraph expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
778+ assertEquals (expected , newSG );
779+ // the Ssurgeon we just created should not put a tag on the word
780+ // but it SHOULD put blue immediately before antennae
781+ blueVertex = newSG .getNodeByIndexSafe (3 );
782+ assertNotNull (blueVertex );
783+ assertNull (blueVertex .tag ());
784+ assertEquals ("blue" , blueVertex .value ());
785+
786+ Map <String , String > expectedFeatures = new HashMap <String , String >() {{
787+ put ("a" , "b" );
788+ put ("c" , "d" );
789+ }};
790+ assertEquals (expectedFeatures , blueVertex .get (CoreAnnotations .CoNLLUFeats .class ));
791+ }
792+
750793 /**
751794 * Set the language when adding a dep. Should create a UniversalEnglish dependency
752795 */
0 commit comments