Skip to content

Commit b606bec

Browse files
committed
Add a test to Ssurgeon - removeEdge already works as we expect it to
1 parent e870f2a commit b606bec

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SsurgeonTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ public void readXMLAddEdgeIterate() {
8484
assertEquals(newSg, expected);
8585
}
8686

87+
/**
88+
* Test that removing an edge given its endpoints and the dependency type will remove all matching edges
89+
*/
90+
@Test
91+
public void readXMLRemoveEdgeIterate() {
92+
String doc = String.join(newline,
93+
"<ssurgeon-pattern-list>",
94+
" <ssurgeon-pattern>",
95+
" <uid>38</uid>",
96+
" <notes>This is a simple test of addEdge</notes>",
97+
" <semgrex>" + XMLUtils.escapeXML("{}=a1 > {}=a2") + "</semgrex>",
98+
" <edit-list>removeEdge -gov a1 -dep a2 -reln dep</edit-list>",
99+
" </ssurgeon-pattern>",
100+
"</ssurgeon-pattern-list>");
101+
Ssurgeon inst = Ssurgeon.inst();
102+
List<SsurgeonPattern> patterns = inst.readFromString(doc);
103+
assertEquals(patterns.size(), 1);
104+
SsurgeonPattern pattern = patterns.get(0);
105+
106+
SemanticGraph sg = SemanticGraph.valueOf("[A-0 obj> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]");
107+
SemanticGraph newSg = pattern.iterate(sg);
108+
SemanticGraph expected = SemanticGraph.valueOf("[A-0 obj> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]");
109+
assertEquals(newSg, sg);
110+
111+
sg = SemanticGraph.valueOf("[A-0 obj> B-1 dep> B-1 obj> C-2 nsubj> [D-3 obj> E-4]]");
112+
newSg = pattern.iterate(sg);
113+
assertEquals(newSg, expected);
114+
115+
sg = 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]]");
116+
newSg = pattern.iterate(sg);
117+
assertEquals(newSg, expected);
118+
}
119+
87120
/**
88121
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
89122
* a semgrex pattern, and then the resulting actions over the named nodes in the

0 commit comments

Comments
 (0)