@@ -1494,6 +1494,93 @@ public void readXMLEditNode() {
14941494 assertEquals ("blue" , blueVertex .value ());
14951495 }
14961496
1497+ /**
1498+ * Test that trying to build an EditNode with an illegal removed attribute fails
1499+ */
1500+ @ Test
1501+ public void readXMLEditNodeIllegalRemove () {
1502+ // sanity check that the key we will use does not actually mean anything
1503+ String missingKey = "zzzzzz" ;
1504+ assertNull (AnnotationLookup .toCoreKey (missingKey ));
1505+
1506+ try {
1507+ Ssurgeon inst = Ssurgeon .inst ();
1508+ String remove = String .join (newline ,
1509+ "<ssurgeon-pattern-list>" ,
1510+ " <ssurgeon-pattern>" ,
1511+ " <uid>38</uid>" ,
1512+ " <notes>Edit a node</notes>" ,
1513+ " <semgrex>" + XMLUtils .escapeXML ("{word:blue}=blue" ) + "</semgrex>" ,
1514+ " <edit-list>EditNode -node blue -remove " + missingKey + "</edit-list>" ,
1515+ " </ssurgeon-pattern>" ,
1516+ "</ssurgeon-pattern-list>" );
1517+ inst .readFromString (remove );
1518+ throw new AssertionError ("Expected a parse exception!" );
1519+ } catch (SsurgeonParseException e ) {
1520+ // yay
1521+ }
1522+ }
1523+
1524+ /**
1525+ * Check that we can add and remove lemmas using EditNode
1526+ *
1527+ * Specially testing that the remove functionality works
1528+ */
1529+ @ Test
1530+ public void readXMLEditNodeRemove () {
1531+ Ssurgeon inst = Ssurgeon .inst ();
1532+
1533+ // use "dep" as the dependency so as to be language-agnostic in this test
1534+ String add = String .join (newline ,
1535+ "<ssurgeon-pattern-list>" ,
1536+ " <ssurgeon-pattern>" ,
1537+ " <uid>38</uid>" ,
1538+ " <notes>Edit a node</notes>" ,
1539+ " <semgrex>" + XMLUtils .escapeXML ("{word:blue}=blue" ) + "</semgrex>" ,
1540+ " <edit-list>EditNode -node blue -lemma blue</edit-list>" ,
1541+ " </ssurgeon-pattern>" ,
1542+ "</ssurgeon-pattern-list>" );
1543+ List <SsurgeonPattern > patterns = inst .readFromString (add );
1544+ assertEquals (patterns .size (), 1 );
1545+ SsurgeonPattern editSsurgeon = patterns .get (0 );
1546+
1547+ SemanticGraph sg = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
1548+ IndexedWord blueVertex = sg .getNodeByIndexSafe (3 );
1549+ assertEquals ("blue" , blueVertex .value ());
1550+ assertNull (blueVertex .lemma ());
1551+
1552+ SemanticGraph newSG = editSsurgeon .iterate (sg ).first ;
1553+ SemanticGraph expected = SemanticGraph .valueOf ("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> blue-3]]" );
1554+ assertEquals (expected , newSG );
1555+ // this ssurgeon will fix the color of the antennae
1556+ blueVertex = newSG .getNodeByIndexSafe (3 );
1557+ assertNotNull (blueVertex );
1558+ assertNull (blueVertex .tag ());
1559+ assertEquals ("blue" , blueVertex .value ());
1560+ assertEquals ("blue" , blueVertex .lemma ());
1561+
1562+ String remove = String .join (newline ,
1563+ "<ssurgeon-pattern-list>" ,
1564+ " <ssurgeon-pattern>" ,
1565+ " <uid>38</uid>" ,
1566+ " <notes>Edit a node</notes>" ,
1567+ " <semgrex>" + XMLUtils .escapeXML ("{word:blue}=blue" ) + "</semgrex>" ,
1568+ " <edit-list>EditNode -node blue -remove lemma</edit-list>" ,
1569+ " </ssurgeon-pattern>" ,
1570+ "</ssurgeon-pattern-list>" );
1571+ patterns = inst .readFromString (remove );
1572+ assertEquals (patterns .size (), 1 );
1573+ editSsurgeon = patterns .get (0 );
1574+
1575+ SemanticGraph noLemmaSG = editSsurgeon .iterate (newSG ).first ;
1576+ assertEquals (expected , noLemmaSG );
1577+ blueVertex = noLemmaSG .getNodeByIndexSafe (3 );
1578+ assertNotNull (blueVertex );
1579+ assertNull (blueVertex .tag ());
1580+ assertEquals ("blue" , blueVertex .value ());
1581+ assertNull (blueVertex .lemma ());
1582+ }
1583+
14971584 /**
14981585 * A couple tests of updating the morpho map on a word using EditNode
14991586 * <br>
@@ -2200,4 +2287,12 @@ public void simpleTest() {
22002287 String firstGraphString = newSgs .iterator ().next ().toCompactString ().trim ();
22012288 assertEquals ("[bartender nsubj>Joe det>the cop>is]" , firstGraphString );
22022289 }
2290+
2291+ /**
2292+ * Test that a couple fields used in Ssurgeon don't conflict with annotation keys in AnnotationLookup
2293+ */
2294+ @ Test
2295+ public void annotationNamesTest () {
2296+ assertNull (AnnotationLookup .toCoreKey (Ssurgeon .REMOVE ));
2297+ }
22032298}
0 commit comments