Skip to content

Commit 23a8952

Browse files
committed
Align some whitespace for better readability in Ssurgeon
1 parent 73f0163 commit 23a8952

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,48 @@
1414

1515
public class SsurgeonTest {
1616

17-
/**
18-
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
19-
* a semgrex pattern, and then the resulting actions over the named nodes in the
20-
* semgrex match.
21-
*/
22-
@Test
23-
public void simpleTest() throws Exception {
24-
SemanticGraph sg = SemanticGraph.valueOf("[mixed/VBN nsubj>[Joe/NNP appos>[bartender/NN det>the/DT]] obj>[drink/NN det>a/DT]]");
25-
SemgrexPattern semgrexPattern = SemgrexPattern.compile("{}=a1 >appos=e1 {}=a2 <nsubj=e2 {}=a3");
26-
SsurgeonPattern pattern = new SsurgeonPattern(semgrexPattern);
27-
28-
System.out.println("Start = "+sg.toCompactString());
29-
30-
// Find and snip the appos and root to nsubj links
31-
SsurgeonEdit apposSnip = new RemoveNamedEdge("e1", "a1", "a2");
32-
pattern.addEdit(apposSnip);
33-
34-
SsurgeonEdit nsubjSnip = new RemoveNamedEdge("e2", "a3", "a1");
35-
pattern.addEdit(nsubjSnip);
36-
37-
// Attach Joe to be the nsubj of bartender
38-
SsurgeonEdit reattachSubj = new AddEdge("a2", "a1", EnglishGrammaticalRelations.NOMINAL_SUBJECT);
39-
pattern.addEdit(reattachSubj);
40-
41-
// Attach copula
42-
IndexedWord isNode = new IndexedWord();
43-
isNode.set(CoreAnnotations.TextAnnotation.class, "is");
44-
isNode.set(CoreAnnotations.LemmaAnnotation.class, "is");
45-
isNode.set(CoreAnnotations.OriginalTextAnnotation.class, "is");
46-
isNode.set(CoreAnnotations.PartOfSpeechAnnotation.class, "VBN");
47-
SsurgeonEdit addCopula = new AddDep("a2", EnglishGrammaticalRelations.COPULA, isNode);
48-
pattern.addEdit(addCopula);
49-
50-
// Destroy subgraph
51-
SsurgeonEdit destroySubgraph = new DeleteGraphFromNode("a3");
52-
pattern.addEdit(destroySubgraph);
53-
54-
// Process and output modified
55-
Collection<SemanticGraph> newSgs = pattern.execute(sg);
56-
for (SemanticGraph newSg : newSgs)
57-
System.out.println("Modified = "+newSg.toCompactString());
58-
String firstGraphString = newSgs.iterator().next().toCompactString().trim();
59-
assertEquals(firstGraphString, "[bartender cop>is nsubj>Joe det>the]");
60-
}
17+
/**
18+
* Simple test of an Ssurgeon edit script. This instances a simple semantic graph,
19+
* a semgrex pattern, and then the resulting actions over the named nodes in the
20+
* semgrex match.
21+
*/
22+
@Test
23+
public void simpleTest() throws Exception {
24+
SemanticGraph sg = SemanticGraph.valueOf("[mixed/VBN nsubj>[Joe/NNP appos>[bartender/NN det>the/DT]] obj>[drink/NN det>a/DT]]");
25+
SemgrexPattern semgrexPattern = SemgrexPattern.compile("{}=a1 >appos=e1 {}=a2 <nsubj=e2 {}=a3");
26+
SsurgeonPattern pattern = new SsurgeonPattern(semgrexPattern);
27+
28+
System.out.println("Start = "+sg.toCompactString());
29+
30+
// Find and snip the appos and root to nsubj links
31+
SsurgeonEdit apposSnip = new RemoveNamedEdge("e1", "a1", "a2");
32+
pattern.addEdit(apposSnip);
33+
34+
SsurgeonEdit nsubjSnip = new RemoveNamedEdge("e2", "a3", "a1");
35+
pattern.addEdit(nsubjSnip);
36+
37+
// Attach Joe to be the nsubj of bartender
38+
SsurgeonEdit reattachSubj = new AddEdge("a2", "a1", EnglishGrammaticalRelations.NOMINAL_SUBJECT);
39+
pattern.addEdit(reattachSubj);
40+
41+
// Attach copula
42+
IndexedWord isNode = new IndexedWord();
43+
isNode.set(CoreAnnotations.TextAnnotation.class, "is");
44+
isNode.set(CoreAnnotations.LemmaAnnotation.class, "is");
45+
isNode.set(CoreAnnotations.OriginalTextAnnotation.class, "is");
46+
isNode.set(CoreAnnotations.PartOfSpeechAnnotation.class, "VBN");
47+
SsurgeonEdit addCopula = new AddDep("a2", EnglishGrammaticalRelations.COPULA, isNode);
48+
pattern.addEdit(addCopula);
49+
50+
// Destroy subgraph
51+
SsurgeonEdit destroySubgraph = new DeleteGraphFromNode("a3");
52+
pattern.addEdit(destroySubgraph);
53+
54+
// Process and output modified
55+
Collection<SemanticGraph> newSgs = pattern.execute(sg);
56+
for (SemanticGraph newSg : newSgs)
57+
System.out.println("Modified = "+newSg.toCompactString());
58+
String firstGraphString = newSgs.iterator().next().toCompactString().trim();
59+
assertEquals(firstGraphString, "[bartender cop>is nsubj>Joe det>the]");
60+
}
6161
}

0 commit comments

Comments
 (0)