Skip to content

Commit 861f72f

Browse files
committed
Add a test to check that the -updateMorphoFeatures EditNode option works
1 parent a37afbb commit 861f72f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,57 @@ public void readXMLEditNode() {
13961396
assertEquals("blue", blueVertex.value());
13971397
}
13981398

1399+
/**
1400+
* A couple tests of updating the morpho map on a word using EditNode
1401+
* <br>
1402+
* -updateMorphoFeatures should update w/o overwriting the whole map
1403+
*/
1404+
@Test
1405+
public void readXMLEditNodeUpdateMorpho() {
1406+
Ssurgeon inst = Ssurgeon.inst();
1407+
1408+
// This should add two morpho features to the word
1409+
// (and should not crash even though the word previously had no features)
1410+
String editPattern = String.join(newline,
1411+
"<ssurgeon-pattern-list>",
1412+
" <ssurgeon-pattern>",
1413+
" <uid>38</uid>",
1414+
" <notes>Edit a node's morpho</notes>",
1415+
" <semgrex>" + XMLUtils.escapeXML("{word:/antennae/}=word") + "</semgrex>",
1416+
" <edit-list>EditNode -node word -updateMorphoFeatures a=b|c=d</edit-list>",
1417+
" </ssurgeon-pattern>",
1418+
"</ssurgeon-pattern-list>");
1419+
1420+
List<SsurgeonPattern> patterns = inst.readFromString(editPattern);
1421+
assertEquals(patterns.size(), 1);
1422+
SsurgeonPattern editSsurgeon = patterns.get(0);
1423+
1424+
SemanticGraph sg = SemanticGraph.valueOf("[has-2 nsubj> Jennifer-1 obj> [antennae-4 dep> green-3]]");
1425+
SemanticGraph newSG = editSsurgeon.iterate(sg).first;
1426+
IndexedWord vertex = sg.getNodeByIndexSafe(4);
1427+
assertEquals("antennae", vertex.value());
1428+
assertEquals(vertex.get(CoreAnnotations.CoNLLUFeats.class).toString(), "a=b|c=d");
1429+
1430+
// This will add a third feature and update one of the existing features,
1431+
// leaving the other feature unchanged
1432+
editPattern = String.join(newline,
1433+
"<ssurgeon-pattern-list>",
1434+
" <ssurgeon-pattern>",
1435+
" <uid>38</uid>",
1436+
" <notes>Edit a node's morpho</notes>",
1437+
" <semgrex>" + XMLUtils.escapeXML("{word:/antennae/}=word") + "</semgrex>",
1438+
" <edit-list>EditNode -node word -updateMorphoFeatures a=zzz|e=f</edit-list>",
1439+
" </ssurgeon-pattern>",
1440+
"</ssurgeon-pattern-list>");
1441+
1442+
patterns = inst.readFromString(editPattern);
1443+
assertEquals(patterns.size(), 1);
1444+
editSsurgeon = patterns.get(0);
1445+
1446+
newSG = editSsurgeon.iterate(sg).first;
1447+
assertEquals(vertex.get(CoreAnnotations.CoNLLUFeats.class).toString(), "a=zzz|c=d|e=f");
1448+
}
1449+
13991450
/**
14001451
* A couple tests of setting the morpho features on a word using EditNode
14011452
*/

0 commit comments

Comments
 (0)