Skip to content

Commit bff3588

Browse files
committed
When creating a NodePattern from NodeAttributes in Semgrex, pass around the NodeAttributes as a single object instead of passing individual pieces. Will make it easier to add more pieces to the NodeAttributes
1 parent 4bdd5fd commit bff3588

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/edu/stanford/nlp/semgraph/semgrex/NodeAttributes.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.stanford.nlp.semgraph.semgrex;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
45
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Set;
@@ -60,6 +61,6 @@ public void setAttribute(String key, String value, boolean negated) {
6061
}
6162

6263
public List<Triple<String, String, Boolean>> attributes() {
63-
return attributes;
64+
return Collections.unmodifiableList(attributes);
6465
}
6566
}

src/edu/stanford/nlp/semgraph/semgrex/NodePattern.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,23 @@ public class NodePattern extends SemgrexPattern {
4343
private List<Pair<Integer, String>> variableGroups;
4444

4545
public NodePattern(GraphRelation r, boolean negDesc,
46-
List<Triple<String, String, Boolean>> attrs,
47-
boolean root, boolean empty, boolean isLink, String name) {
48-
this(r, negDesc, attrs, root, empty, isLink, name,
46+
NodeAttributes attrs, boolean isLink, String name) {
47+
this(r, negDesc, attrs, isLink, name,
4948
new ArrayList<>(0));
5049
}
5150

5251
// TODO: there is no capacity for named variable groups in the parser right now
5352
public NodePattern(GraphRelation r, boolean negDesc,
54-
List<Triple<String, String, Boolean>> attrs,
55-
boolean root, boolean empty, boolean isLink, String name,
53+
NodeAttributes attrs, boolean isLink, String name,
5654
List<Pair<Integer, String>> variableGroups) {
5755
this.reln = r;
5856
this.negDesc = negDesc;
5957
this.isLink = isLink;
6058
// order the attributes so that the pattern stays the same when
6159
// printing a compiled pattern
62-
attributes = new ArrayList<>();
60+
this.attributes = new ArrayList<>();
6361
descString = "{";
64-
for (Triple<String, String, Boolean> entry : attrs) {
62+
for (Triple<String, String, Boolean> entry : attrs.attributes()) {
6563
if (!descString.equals("{"))
6664
descString += ";";
6765
String key = entry.first();
@@ -100,12 +98,12 @@ public NodePattern(GraphRelation r, boolean negDesc,
10098
}
10199
}
102100

103-
if (root) {
101+
if (attrs.root()) {
104102
if (!descString.equals("{"))
105103
descString += ";";
106104
descString += "$";
107105
}
108-
if (empty) {
106+
if (attrs.empty()) {
109107
if (!descString.equals("{"))
110108
descString += ";";
111109
descString += "#";
@@ -114,8 +112,8 @@ public NodePattern(GraphRelation r, boolean negDesc,
114112

115113
this.name = name;
116114
this.child = null;
117-
this.isRoot = root;
118-
this.isEmpty = empty;
115+
this.isRoot = attrs.root();
116+
this.isEmpty = attrs.empty();
119117

120118
this.variableGroups = Collections.unmodifiableList(variableGroups);
121119
}

src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
632632
jj_la1[28] = jj_gen;
633633
;
634634
}
635-
pat = new NodePattern(r, underNodeNegation, attributes.attributes(), attributes.root(), attributes.empty(), link, name != null ? name.image : null);
635+
pat = new NodePattern(r, underNodeNegation, attributes, link, name != null ? name.image : null);
636636
{if ("" != null) return pat;}
637637
throw new Error("Missing return statement in function");
638638
}

src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ NodePattern Description(GraphRelation r) : {
310310
}
311311
)?
312312
)
313-
{ pat = new NodePattern(r, underNodeNegation, attributes.attributes(), attributes.root(), attributes.empty(), link, name != null ? name.image : null);
313+
{ pat = new NodePattern(r, underNodeNegation, attributes, link, name != null ? name.image : null);
314314
return pat;
315315
}
316316
}

0 commit comments

Comments
 (0)