1010import edu .stanford .nlp .ling .CoreAnnotations ;
1111import edu .stanford .nlp .ling .IndexedWord ;
1212import edu .stanford .nlp .semgraph .SemanticGraph ;
13+ import edu .stanford .nlp .semgraph .SemanticGraphEdge ;
1314import edu .stanford .nlp .semgraph .semgrex .SemgrexPattern ;
1415import edu .stanford .nlp .trees .EnglishGrammaticalRelations ;
16+ import edu .stanford .nlp .util .XMLUtils ;
1517
1618public class SsurgeonTest {
1719
@@ -31,15 +33,16 @@ public void readXMLEmptyPattern() {
3133 assertEquals (pattern .size (), 1 );
3234 }
3335
36+ static final String newline = System .getProperty ("line.separator" );
37+
3438 @ Test
35- public void readXMLEdit () {
36- String newline = System .getProperty ("line.separator" );
39+ public void readXMLAddEdgeExecute () {
3740 String doc = String .join (newline ,
3841 "<ssurgeon-pattern-list>" ,
3942 " <ssurgeon-pattern>" ,
4043 " <uid>38</uid>" ,
4144 " <notes>This is a simple test of addEdge</notes>" ,
42- " <semgrex>{}=a1 > {}=a2</semgrex>" ,
45+ " <semgrex>" + XMLUtils . escapeXML ( " {}=a1 > {}=a2" ) + " </semgrex>" ,
4346 " <edit-list>addEdge -gov a1 -dep a2 -reln dep -weight 0.5</edit-list>" ,
4447 " </ssurgeon-pattern>" ,
4548 "</ssurgeon-pattern-list>" );
@@ -50,11 +53,37 @@ public void readXMLEdit() {
5053
5154 SemanticGraph sg = SemanticGraph .valueOf ("[A obj> B obj> C]" );
5255 Collection <SemanticGraph > newSgs = pattern .execute (sg );
53- // TODO: perhaps it would be better to have an execution scheme
54- // where one graph has all possible modifications applied
5556 assertEquals (newSgs .size (), 2 );
5657 }
5758
59+
60+ /**
61+ * Test that AddEdge, when iterated, adds exactly one more edge
62+ * between each parent/child pair if they matched the target relation
63+ */
64+ @ Test
65+ public void readXMLAddEdgeIterate () {
66+ String doc = String .join (newline ,
67+ "<ssurgeon-pattern-list>" ,
68+ " <ssurgeon-pattern>" ,
69+ " <uid>38</uid>" ,
70+ " <notes>This is a simple test of addEdge</notes>" ,
71+ " <semgrex>" + XMLUtils .escapeXML ("{}=a1 >obj {}=a2" ) + "</semgrex>" ,
72+ " <edit-list>addEdge -gov a1 -dep a2 -reln dep -weight 0.5</edit-list>" ,
73+ " </ssurgeon-pattern>" ,
74+ "</ssurgeon-pattern-list>" );
75+ Ssurgeon inst = Ssurgeon .inst ();
76+ List <SsurgeonPattern > patterns = inst .readFromString (doc );
77+ assertEquals (patterns .size (), 1 );
78+ SsurgeonPattern pattern = patterns .get (0 );
79+
80+ SemanticGraph sg = SemanticGraph .valueOf ("[A obj> B obj> C nsubj> [D obj> E]]" );
81+ SemanticGraph newSg = pattern .iterate (sg );
82+ SemanticGraph expected = SemanticGraph .valueOf ("[A-0 obj> B-1 dep> B-1 obj> C-2 dep> C-2 nsubj> [D-3 obj> E-4 dep> E-4]]" );
83+
84+ assertEquals (newSg , expected );
85+ }
86+
5887 /**
5988 * Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
6089 * a semgrex pattern, and then the resulting actions over the named nodes in the
0 commit comments