@@ -1204,6 +1204,57 @@ public void readXMLEditNode() {
12041204 }
12051205
12061206
1207+ /**
1208+ * Put MWT annotations on a couple nodes using EditNode
1209+ */
1210+ @ Test
1211+ public void readXMLEditNodeMWT () {
1212+ Ssurgeon inst = Ssurgeon .inst ();
1213+
1214+ // use "dep" as the dependency so as to be language-agnostic in this test
1215+ String add = String .join (newline ,
1216+ "<ssurgeon-pattern-list>" ,
1217+ " <ssurgeon-pattern>" ,
1218+ " <uid>38</uid>" ,
1219+ " <notes>Edit a node's MWT</notes>" ,
1220+ " <semgrex>" + XMLUtils .escapeXML ("{word:/[iI]t/}=it . {word:/'s/}=s" ) + "</semgrex>" ,
1221+ " <edit-list>EditNode -node it -is_mwt true -is_first_mwt true -mwt_text it's</edit-list>" ,
1222+ " <edit-list>EditNode -node s -is_mwt true -is_first_mwt false -mwt_text it's</edit-list>" ,
1223+ " </ssurgeon-pattern>" ,
1224+ "</ssurgeon-pattern-list>" );
1225+ List <SsurgeonPattern > patterns = inst .readFromString (add );
1226+ assertEquals (patterns .size (), 1 );
1227+ SsurgeonPattern editSsurgeon = patterns .get (0 );
1228+
1229+ SemanticGraph sg = SemanticGraph .valueOf ("[yours-4 nsubj> it-1 cop> 's-2 advmod> yours-3 punct> !-5]" );
1230+
1231+ // check the original values
1232+ IndexedWord itVertex = sg .getNodeByIndexSafe (1 );
1233+ assertEquals (null , itVertex .get (CoreAnnotations .IsMultiWordTokenAnnotation .class ));
1234+ assertEquals (null , itVertex .get (CoreAnnotations .IsFirstWordOfMWTAnnotation .class ));
1235+ assertEquals (null , itVertex .get (CoreAnnotations .MWTTokenTextAnnotation .class ));
1236+ IndexedWord sVertex = sg .getNodeByIndexSafe (2 );
1237+ assertEquals (null , sVertex .get (CoreAnnotations .IsMultiWordTokenAnnotation .class ));
1238+ assertEquals (null , sVertex .get (CoreAnnotations .IsFirstWordOfMWTAnnotation .class ));
1239+ assertEquals (null , sVertex .get (CoreAnnotations .MWTTokenTextAnnotation .class ));
1240+
1241+ SemanticGraph newSG = editSsurgeon .iterate (sg );
1242+ // the high level graph structure won't change
1243+ SemanticGraph expected = SemanticGraph .valueOf ("[yours-4 nsubj> it-1 cop> 's-2 advmod> yours-3 punct> !-5]" );
1244+ assertEquals (expected , newSG );
1245+
1246+ // check the updates
1247+ itVertex = newSG .getNodeByIndexSafe (1 );
1248+ assertTrue (itVertex .get (CoreAnnotations .IsMultiWordTokenAnnotation .class ));
1249+ assertTrue (itVertex .get (CoreAnnotations .IsFirstWordOfMWTAnnotation .class ));
1250+ assertEquals ("it's" , itVertex .get (CoreAnnotations .MWTTokenTextAnnotation .class ));
1251+ sVertex = newSG .getNodeByIndexSafe (2 );
1252+ assertTrue (sVertex .get (CoreAnnotations .IsMultiWordTokenAnnotation .class ));
1253+ assertFalse (sVertex .get (CoreAnnotations .IsFirstWordOfMWTAnnotation .class ));
1254+ assertEquals ("it's" , sVertex .get (CoreAnnotations .MWTTokenTextAnnotation .class ));
1255+ }
1256+
1257+
12071258 /**
12081259 * Test that we don't allow changing a word index, for example, in EditNode or AddDep
12091260 */
0 commit comments