Skip to content

Commit 867ae59

Browse files
committed
Executes a single addEdge. Perhaps need to investigate making this work multiple times over a single graph instead of returning all possible single modifications of the graph
1 parent 00dde80 commit 867ae59

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@
4040
* loaded can reference these resources.
4141
*<br>
4242
* An Ssurgeon can be built from an XML pattern or by assembling the pieces by hand.
43+
*<br>
44+
* The XML format is as follows:
45+
<pre>
46+
{@code
47+
<ssurgeon-pattern-list>
48+
<ssurgeon-pattern>
49+
<uid>...</uid>
50+
<notes>...</notes>
51+
<semgrex>...</semgrex>
52+
<edit-list>...</edit-list>
53+
</ssurgeon-pattern>
54+
</ssurgeon-pattern-list>
55+
}
56+
</pre>
57+
* The {@code id} is the id of the Ssurgeon operation. <br>
58+
* The {@code notes} are comments on the Ssurgeon. <br>
59+
* The {@code semgrex} is a Semgrex pattern to use when matching for this operation. <br>
60+
* The {@code edit-list} is the actual Ssurgeon operation to execute. <br>
61+
*
62+
* Available operations and their arguments include:
63+
* <ul>
64+
* <li> {@code addEdge -gov a1 -dep a2 -reln dep -weight 0.5}
65+
* </ul>
4366
*
4467
* @author Eric Yeh
4568
*/
@@ -242,7 +265,7 @@ protected static class SsurgeonArgs {
242265
// below are string representations of the intended values
243266
public String nodeString = null;
244267

245-
public double weight = 1.0;
268+
public double weight = 0.0;
246269

247270
public String name = null;
248271
}
@@ -333,7 +356,7 @@ public static SsurgeonEdit parseEditLine(String editLine) {
333356
} else if (command.equalsIgnoreCase(AddNode.LABEL)) {
334357
retEdit = AddNode.createAddNode(argsBox.nodeString, argsBox.name);
335358
} else if (command.equalsIgnoreCase(AddEdge.LABEL)) {
336-
retEdit = AddEdge.createEngAddEdge(argsBox.govNodeName, argsBox.dep, argsBox.reln);
359+
retEdit = AddEdge.createEngAddEdge(argsBox.govNodeName, argsBox.dep, argsBox.reln, argsBox.weight);
337360
} else if (command.equalsIgnoreCase(DeleteGraphFromNode.LABEL)) {
338361
retEdit = new DeleteGraphFromNode(argsBox.node);
339362
} else if (command.equalsIgnoreCase(RemoveEdge.LABEL)) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ public void readXMLEmptyPattern() {
2828
"</ssurgeon-pattern-list>");
2929
Ssurgeon inst = Ssurgeon.inst();
3030
List<SsurgeonPattern> pattern = inst.readFromString(doc);
31+
assertEquals(pattern.size(), 1);
32+
}
33+
34+
@Test
35+
public void readXMLEdit() {
36+
String newline = System.getProperty("line.separator");
37+
String doc = String.join(newline,
38+
"<ssurgeon-pattern-list>",
39+
" <ssurgeon-pattern>",
40+
" <uid>38</uid>",
41+
" <notes>This is a simple test of addEdge</notes>",
42+
" <semgrex>{}=a1 &gt; {}=a2</semgrex>",
43+
" <edit-list>addEdge -gov a1 -dep a2 -reln dep -weight 0.5</edit-list>",
44+
" </ssurgeon-pattern>",
45+
"</ssurgeon-pattern-list>");
46+
Ssurgeon inst = Ssurgeon.inst();
47+
List<SsurgeonPattern> patterns = inst.readFromString(doc);
48+
assertEquals(patterns.size(), 1);
49+
SsurgeonPattern pattern = patterns.get(0);
50+
51+
SemanticGraph sg = SemanticGraph.valueOf("[A obj> B obj> C]");
52+
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
55+
assertEquals(newSgs.size(), 2);
3156
}
3257

3358
/**

0 commit comments

Comments
 (0)