@@ -1322,6 +1322,110 @@ public void forbidIllegalAttributes() {
1322
1322
}
1323
1323
}
1324
1324
1325
+ /**
1326
+ * Test a two step process to reattach an edge elsewhere
1327
+ *<br>
1328
+ * Uses a real example from UD_English-Pronouns
1329
+ */
1330
+ @ Test
1331
+ public void readXMLTwoStepReattach () {
1332
+ String doc = String .join (newline ,
1333
+ "<ssurgeon-pattern-list>" ,
1334
+ " <ssurgeon-pattern>" ,
1335
+ " <uid>38</uid>" ,
1336
+ " <notes>This tests the two step process of reattaching an edge</notes>" ,
1337
+ " <language>UniversalEnglish</language>" ,
1338
+ " <semgrex>" + XMLUtils .escapeXML ("{word:/[.]/}=punct <punct=bad {}=parent << {$}=root : {}=parent << {}=root" ) + "</semgrex>" ,
1339
+ " <edit-list>removeNamedEdge -edge bad</edit-list>" ,
1340
+ " <edit-list>addEdge -gov root -dep punct -reln punct</edit-list>" ,
1341
+ " </ssurgeon-pattern>" ,
1342
+ "</ssurgeon-pattern-list>" );
1343
+ Ssurgeon inst = Ssurgeon .inst ();
1344
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
1345
+ assertEquals (patterns .size (), 1 );
1346
+ SsurgeonPattern pattern = patterns .get (0 );
1347
+
1348
+ // check a simple case of relabeling
1349
+ SemanticGraph sg = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 csubj> [clean-5 mark> to-4 punct> .-6]]" );
1350
+ SemanticGraph expected = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 punct> .-6 csubj> [clean-5 mark> to-4]]" );
1351
+ SemanticGraph newSg = pattern .iterate (sg );
1352
+ assertEquals (newSg , expected );
1353
+ }
1354
+
1355
+ /**
1356
+ * Test reattachNamedEdge, which is a one step version of reattaching where an edge goes
1357
+ *<br>
1358
+ * Uses a real example from UD_English-Pronouns
1359
+ */
1360
+ @ Test
1361
+ public void readXMLOneStepReattach () {
1362
+ String doc = String .join (newline ,
1363
+ "<ssurgeon-pattern-list>" ,
1364
+ " <ssurgeon-pattern>" ,
1365
+ " <uid>38</uid>" ,
1366
+ " <notes>This tests the two step process of reattaching an edge</notes>" ,
1367
+ " <language>UniversalEnglish</language>" ,
1368
+ " <semgrex>" + XMLUtils .escapeXML ("{word:/[.]/}=punct <punct=bad {}=parent << {$}=root : {}=parent << {}=root" ) + "</semgrex>" ,
1369
+ " <edit-list>reattachNamedEdge -edge bad -gov root</edit-list>" ,
1370
+ " </ssurgeon-pattern>" ,
1371
+ "</ssurgeon-pattern-list>" );
1372
+ Ssurgeon inst = Ssurgeon .inst ();
1373
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
1374
+ assertEquals (patterns .size (), 1 );
1375
+ SsurgeonPattern pattern = patterns .get (0 );
1376
+
1377
+ // check a simple case of relabeling
1378
+ SemanticGraph sg = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 csubj> [clean-5 mark> to-4 punct> .-6]]" );
1379
+ SemanticGraph expected = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 punct> .-6 csubj> [clean-5 mark> to-4]]" );
1380
+ SemanticGraph newSg = pattern .iterate (sg );
1381
+ assertEquals (newSg , expected );
1382
+
1383
+ // this tests -gov and -dep both set
1384
+ doc = String .join (newline ,
1385
+ "<ssurgeon-pattern-list>" ,
1386
+ " <ssurgeon-pattern>" ,
1387
+ " <uid>38</uid>" ,
1388
+ " <notes>This tests the two step process of reattaching an edge</notes>" ,
1389
+ " <language>UniversalEnglish</language>" ,
1390
+ " <semgrex>" + XMLUtils .escapeXML ("{word:/[.]/}=punct <punct=bad {}=parent << {$}=root : {}=parent << {}=root" ) + "</semgrex>" ,
1391
+ " <edit-list>reattachNamedEdge -edge bad -gov root -dep punct</edit-list>" ,
1392
+ " </ssurgeon-pattern>" ,
1393
+ "</ssurgeon-pattern-list>" );
1394
+ inst = Ssurgeon .inst ();
1395
+ patterns = inst .readFromString (doc );
1396
+ assertEquals (patterns .size (), 1 );
1397
+ pattern = patterns .get (0 );
1398
+
1399
+ // check a simple case of relabeling, this time with the (unnecessary) -dep specifier as well
1400
+ sg = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 csubj> [clean-5 mark> to-4 punct> .-6]]" );
1401
+ expected = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 punct> .-6 csubj> [clean-5 mark> to-4]]" );
1402
+ newSg = pattern .iterate (sg );
1403
+ assertEquals (newSg , expected );
1404
+
1405
+ // this tests -dep set by itself (although the operation itself is nonsense)
1406
+ doc = String .join (newline ,
1407
+ "<ssurgeon-pattern-list>" ,
1408
+ " <ssurgeon-pattern>" ,
1409
+ " <uid>38</uid>" ,
1410
+ " <notes>This tests the two step process of reattaching an edge</notes>" ,
1411
+ " <language>UniversalEnglish</language>" ,
1412
+ " <semgrex>" + XMLUtils .escapeXML ("{$}=root >csubj=foo ({word:clean}=n1 >mark=bar {}=n2)" ) + "</semgrex>" ,
1413
+ " <edit-list>reattachNamedEdge -edge foo -dep n2</edit-list>" ,
1414
+ " <edit-list>reattachNamedEdge -edge bar -gov n2 -dep n1</edit-list>" ,
1415
+ " </ssurgeon-pattern>" ,
1416
+ "</ssurgeon-pattern-list>" );
1417
+ inst = Ssurgeon .inst ();
1418
+ patterns = inst .readFromString (doc );
1419
+ assertEquals (patterns .size (), 1 );
1420
+ pattern = patterns .get (0 );
1421
+
1422
+ // do some random rearranging to force a test of reattachNamedEdge with -dep set
1423
+ sg = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 csubj> [clean-5 mark> to-4 punct> .-6]]" );
1424
+ expected = SemanticGraph .valueOf ("[easy-3 nsubj> Hers-1 cop> is-2 csubj> [to-4 mark> [clean-5 punct> .-6]]]" );
1425
+ newSg = pattern .iterate (sg );
1426
+ assertEquals (newSg , expected );
1427
+ }
1428
+
1325
1429
/**
1326
1430
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
1327
1431
* a semgrex pattern, and then the resulting actions over the named nodes in the
0 commit comments