Skip to content

Commit 382055f

Browse files
committed
Scaffolding for the VariableStrings which doesn't do anything yet - would need to parse the strings and match against them in the matchers
Implement part of the SemgrexParser part of the variableGroups change. Unfortunately, it is not correct until we process one matcher per regex rather than trying to keep one matcher for all the attributes
1 parent 8eba4a3 commit 382055f

File tree

8 files changed

+125
-77
lines changed

8 files changed

+125
-77
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,8 @@ public class NodePattern extends SemgrexPattern {
4949
SemgrexPattern child;
5050
// specifies the groups in a regex that are captured as
5151
// matcher-global string variables
52-
private List<Pair<Integer, String>> variableGroups;
52+
private final List<Pair<Integer, String>> variableGroups;
5353

54-
public NodePattern(GraphRelation r, boolean negDesc,
55-
NodeAttributes attrs, boolean isLink, String name) {
56-
this(r, negDesc, attrs, isLink, name,
57-
new ArrayList<>(0));
58-
}
59-
60-
// TODO: there is no capacity for named variable groups in the parser right now
6154
public NodePattern(GraphRelation r, boolean negDesc,
6255
NodeAttributes attrs, boolean isLink, String name,
6356
List<Pair<Integer, String>> variableGroups) {
@@ -586,6 +579,9 @@ private void goToNextNodeMatch() {
586579
edgeNamedFirst = true;
587580
namesToEdges.put(myNode.reln.getEdgeName(), nextMatchEdge);
588581
}
582+
// TODO FIXME: this would need to read all of the matchers used
583+
// (eg, from the various attributes)
584+
// and commit all of them
589585
commitVariableGroups(m); // commit my variable groups.
590586
}
591587
// finished is false exiting this if and only if nextChild exists
@@ -595,7 +591,11 @@ private void goToNextNodeMatch() {
595591

596592
private void commitVariableGroups(Matcher m) {
597593
committedVariables = true; // commit all my variable groups.
594+
if (myNode.variableGroups.size() > 0) {
595+
System.out.println(myNode.variableGroups);
596+
}
598597
for (Pair<Integer, String> varGroup : myNode.variableGroups) {
598+
System.out.println(varGroup);
599599
String thisVarString = m.group(varGroup.first());
600600
variableStrings.setVar(varGroup.second(), thisVarString);
601601
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public SemanticGraphEdge getEdge(String name) {
8181
return namesToEdges.get(name);
8282
}
8383

84+
public String getVariableString(String var) {
85+
return variableStrings.getString(var);
86+
}
87+
8488
public String toString() {
8589
StringBuilder builder = new StringBuilder();
8690
builder.append(matchedPattern);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void reset() {
7777
namesToNodes.clear();
7878
namesToRelations.clear();
7979
namesToEdges.clear();
80+
variableStrings.reset();
8081
}
8182

8283
/**

0 commit comments

Comments
 (0)