@@ -1721,6 +1721,44 @@ public void readXMLOneStepReattach() {
1721
1721
assertEquals (newSg , expected );
1722
1722
}
1723
1723
1724
+
1725
+ /**
1726
+ * Test deleteLeaf, which removes an unwanted leaf and its edges, then renumbers everything
1727
+ *<br>
1728
+ * Uses a real example from UD_Portuguese-GSD
1729
+ */
1730
+ @ Test
1731
+ public void readXMLDeleteLeaf () {
1732
+ String doc = String .join (newline ,
1733
+ "<ssurgeon-pattern-list>" ,
1734
+ " <ssurgeon-pattern>" ,
1735
+ " <uid>38</uid>" ,
1736
+ " <notes>Test deleting a leaf (only if it's a leaf)</notes>" ,
1737
+ " <language>UniversalEnglish</language>" ,
1738
+ // the real life example used POS tags to make sure "verb" and "clitic" are the right pieces
1739
+ " <semgrex>" + XMLUtils .escapeXML ("{}=verb . ({word:/-/}=dash . {word:se}=clitic)" ) + "</semgrex>" ,
1740
+ " <edit-list>combineMWT -node verb -node dash -node clitic</edit-list>" ,
1741
+ " <edit-list>deleteLeaf -node dash</edit-list>" ,
1742
+ " </ssurgeon-pattern>" ,
1743
+ "</ssurgeon-pattern-list>" );
1744
+ Ssurgeon inst = Ssurgeon .inst ();
1745
+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
1746
+ assertEquals (patterns .size (), 1 );
1747
+ SsurgeonPattern pattern = patterns .get (0 );
1748
+
1749
+ // the dash should be removed and all words with an index after the dash should have that index decremented
1750
+ SemanticGraph sg = SemanticGraph .valueOf ("[nobre-6 nmod> [decreto-9 case> com-7 det> o-8] cop> fez-3 punct> --4 expl:pv> [se-5 advmod> [Assim punct> ,-2]]]" );
1751
+ SemanticGraph expected = SemanticGraph .valueOf ("[nobre-5 nmod> [decreto-8 case> com-6 det> o-7] cop> fez-3 expl:pv> [se-4 advmod> [Assim punct> ,-2]]]" );
1752
+ SemanticGraph newSg = pattern .iterate (sg ).first ;
1753
+ assertEquals (newSg , expected );
1754
+
1755
+ // here, the dash isn't a leaf any more, so it shouldn't be deleted
1756
+ sg = SemanticGraph .valueOf ("[nobre-6 nmod> [decreto-9 case> com-7 det> o-8] cop> fez-3 punct> [--4 expl:pv> [se-5 advmod> [Assim punct> ,-2]]]]" );
1757
+ expected = SemanticGraph .valueOf ("[nobre-6 nmod> [decreto-9 case> com-7 det> o-8] cop> fez-3 punct> [--4 expl:pv> [se-5 advmod> [Assim punct> ,-2]]]]" );
1758
+ newSg = pattern .iterate (sg ).first ;
1759
+ assertEquals (newSg , expected );
1760
+ }
1761
+
1724
1762
/**
1725
1763
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
1726
1764
* a semgrex pattern, and then the resulting actions over the named nodes in the
0 commit comments