Skip to content

Commit 2747d8f

Browse files
committed
Add a Sort operation... need to make it properly communicate with the python client, though
1 parent 4bfb0de commit 2747d8f

File tree

8 files changed

+476
-247
lines changed

8 files changed

+476
-247
lines changed

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

Lines changed: 160 additions & 142 deletions
Large diffs are not rendered by default.

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SPECIAL_TOKEN:
7070
TOKEN:
7171
{
7272
< UNIQ: "uniq" >
73+
| < SORT: "sort" >
7374
}
7475

7576
TOKEN:
@@ -90,7 +91,8 @@ SemgrexPattern Root() : {
9091
List<SemgrexPattern> children = new ArrayList<SemgrexPattern>();
9192
Token startToken = null;
9293

93-
List<String> uniqKeys = null;
94+
List<String> postprocessKeys = null;
95+
Token postprocess = null;
9496
Token nextIdentifier = null;
9597
// a local variable
9698
} {
@@ -119,9 +121,9 @@ SemgrexPattern Root() : {
119121
)
120122
(
121123
(
122-
"::" <UNIQ> { uniqKeys = new ArrayList<>(); } (nextIdentifier = identifier() { uniqKeys.add(nextIdentifier.image); })*
124+
"::" (postprocess = <UNIQ> | postprocess = <SORT>) { postprocessKeys = new ArrayList<>(); } (nextIdentifier = identifier() { postprocessKeys.add(nextIdentifier.image); })*
123125
{
124-
for (String key : uniqKeys) {
126+
for (String key : postprocessKeys) {
125127
if (!knownVariables.contains(key) && !knownVarGroups.contains(key) && !knownEdges.contains(key)) {
126128
throw new SemgrexParseException("Semgrex pattern asked for uniq of node " + key + " which does not exist in the pattern (as a node, regex, or edge)");
127129
}
@@ -132,7 +134,11 @@ SemgrexPattern Root() : {
132134
}
133135
}
134136
// TODO: edge names might need some upgrades anyway - shouldn't name them under negation, for example
135-
node = new UniqPattern(node, uniqKeys);
137+
if (postprocess.image.equals("uniq")) {
138+
node = new UniqPattern(node, postprocessKeys);
139+
} else if (postprocess.image.equals("sort")) {
140+
node = new SortPattern(node, postprocessKeys);
141+
}
136142
}
137143
)?
138144
)

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ interface SemgrexParserConstants {
1515
/** RegularExpression Id. */
1616
int UNIQ = 2;
1717
/** RegularExpression Id. */
18-
int RELATION = 3;
18+
int SORT = 3;
1919
/** RegularExpression Id. */
20-
int ALIGNRELN = 4;
20+
int RELATION = 4;
2121
/** RegularExpression Id. */
22-
int IDENTIFIER = 5;
22+
int ALIGNRELN = 5;
2323
/** RegularExpression Id. */
24-
int NUMBER = 6;
24+
int IDENTIFIER = 6;
2525
/** RegularExpression Id. */
26-
int EMPTY = 7;
26+
int NUMBER = 7;
2727
/** RegularExpression Id. */
28-
int ROOT = 8;
28+
int EMPTY = 8;
2929
/** RegularExpression Id. */
30-
int REGEX = 9;
30+
int ROOT = 9;
31+
/** RegularExpression Id. */
32+
int REGEX = 10;
3133

3234
/** Lexical state. */
3335
int DEFAULT = 0;
@@ -37,6 +39,7 @@ interface SemgrexParserConstants {
3739
"<EOF>",
3840
"<WHITESPACE>",
3941
"\"uniq\"",
42+
"\"sort\"",
4043
"<RELATION>",
4144
"\"@\"",
4245
"<IDENTIFIER>",

0 commit comments

Comments
 (0)