Skip to content

Commit

Permalink
Add *number as a parsed item in a Semgrex expression. Not implemented…
Browse files Browse the repository at this point in the history
… in the SemgrexPattern yet, though
  • Loading branch information
AngledLuffa committed Jun 19, 2024
1 parent 935d2fa commit 1ccbebb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 48 deletions.
85 changes: 48 additions & 37 deletions src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
case 11:
case 15:
case 17:
case 22:{
case 23:{
node = SubNode(GraphRelation.ROOT);
children.add(node);
label_1:
Expand Down Expand Up @@ -135,7 +135,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
}
case 15:
case 17:
case 22:{
case 23:{
result = ModNode(r);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case RELATION:
Expand Down Expand Up @@ -294,6 +294,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
Token relnType = null;
Token numArg = null;
Token numArg2 = null;
Token graphNumber = null;
Token name = null;
Token edgeName = null;
SemgrexPattern node;
Expand Down Expand Up @@ -347,7 +348,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 20:{
jj_consume_token(20);
name = jj_consume_token(IDENTIFIER);
graphNumber = jj_consume_token(NUMBER);
break;
}
default:
Expand All @@ -357,21 +358,31 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 21:{
jj_consume_token(21);
edgeName = jj_consume_token(IDENTIFIER);
name = jj_consume_token(IDENTIFIER);
break;
}
default:
jj_la1[15] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 22:{
jj_consume_token(22);
edgeName = jj_consume_token(IDENTIFIER);
break;
}
default:
jj_la1[16] = jj_gen;
;
}
break;
}
case ALIGNRELN:{
rel = jj_consume_token(ALIGNRELN);
break;
}
default:
jj_la1[16] = jj_gen;
jj_la1[17] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -397,7 +408,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 15:
case 17:
case 22:{
case 23:{
node = ModNode(reln);
break;
}
Expand All @@ -408,7 +419,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[17] = jj_gen;
jj_la1[18] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -429,7 +440,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[18] = jj_gen;
jj_la1[19] = jj_gen;
break label_4;
}
jj_consume_token(13);
Expand All @@ -454,12 +465,12 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
case 14:
case 15:
case 17:
case 22:{
case 23:{
;
break;
}
default:
jj_la1[19] = jj_gen;
jj_la1[20] = jj_gen;
break label_5;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
Expand All @@ -468,7 +479,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[20] = jj_gen;
jj_la1[21] = jj_gen;
;
}
child = ModNode(r);
Expand All @@ -485,7 +496,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
boolean startUnderNeg;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 17:
case 22:{
case 23:{
child = Child(r);
break;
}
Expand All @@ -498,7 +509,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[21] = jj_gen;
jj_la1[22] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -512,12 +523,12 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
child = NodeDisj(r);
break;
}
case 22:{
case 23:{
child = Description(r);
break;
}
default:
jj_la1[22] = jj_gen;
jj_la1[23] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -541,7 +552,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[23] = jj_gen;
jj_la1[24] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -559,7 +570,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[24] = jj_gen;
jj_la1[25] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
Expand All @@ -569,7 +580,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
boolean link = false;
NodeAttributes attributes = new NodeAttributes();
NodePattern pat;
jj_consume_token(22);
jj_consume_token(23);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case IDENTIFIER:
case EMPTY:
Expand All @@ -578,27 +589,27 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
label_6:
while (true) {
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 23:{
case 24:{
;
break;
}
default:
jj_la1[25] = jj_gen;
jj_la1[26] = jj_gen;
break label_6;
}
jj_consume_token(23);
jj_consume_token(24);
AddAttribute(attributes);
}
break;
}
default:
jj_la1[26] = jj_gen;
jj_la1[27] = jj_gen;
;
}
jj_consume_token(24);
jj_consume_token(25);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 21:{
jj_consume_token(21);
case 22:{
jj_consume_token(22);
link = true;
name = jj_consume_token(IDENTIFIER);
String nodeName = name.image;
Expand All @@ -612,7 +623,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
break;
}
default:
jj_la1[27] = jj_gen;
jj_la1[28] = jj_gen;
;
}
pat = new NodePattern(r, underNodeNegation, attributes.attributes(), attributes.root(), attributes.empty(), name != null ? name.image : null);
Expand All @@ -630,13 +641,13 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
public Token jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[28];
final private int[] jj_la1 = new int[29];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0x400,0x428808,0x3801c,0x3801c,0x428800,0x2000,0x3c01c,0x4000,0x3801c,0x2001c,0x80000,0x10,0x110,0x110,0x100000,0x200000,0x1c,0x428800,0x2000,0x42c000,0x4000,0x428000,0x420000,0x110,0xd0,0x800000,0xd0,0x200000,};
jj_la1_0 = new int[] {0x400,0x828808,0x3801c,0x3801c,0x828800,0x2000,0x3c01c,0x4000,0x3801c,0x2001c,0x80000,0x10,0x110,0x110,0x100000,0x200000,0x400000,0x1c,0x828800,0x2000,0x82c000,0x4000,0x828000,0x820000,0x110,0xd0,0x1000000,0xd0,0x400000,};
}

/** Constructor with InputStream. */
Expand All @@ -650,7 +661,7 @@ public SemgrexParser(java.io.InputStream stream, String encoding) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

/** Reinitialise. */
Expand All @@ -664,7 +675,7 @@ public void ReInit(java.io.InputStream stream, String encoding) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

/** Constructor. */
Expand All @@ -674,7 +685,7 @@ public SemgrexParser(java.io.Reader stream) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

/** Reinitialise. */
Expand All @@ -692,7 +703,7 @@ public void ReInit(java.io.Reader stream) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

/** Constructor with generated Token Manager. */
Expand All @@ -701,7 +712,7 @@ public SemgrexParser(SemgrexParserTokenManager tm) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

/** Reinitialise. */
Expand All @@ -710,7 +721,7 @@ public void ReInit(SemgrexParserTokenManager tm) {
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 28; i++) jj_la1[i] = -1;
for (int i = 0; i < 29; i++) jj_la1[i] = -1;
}

private Token jj_consume_token(int kind) throws ParseException {
Expand Down Expand Up @@ -761,12 +772,12 @@ private int jj_ntk_f() {
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[25];
boolean[] la1tokens = new boolean[26];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 28; i++) {
for (int i = 0; i < 29; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
Expand All @@ -775,7 +786,7 @@ public ParseException generateParseException() {
}
}
}
for (int i = 0; i < 25; i++) {
for (int i = 0; i < 26; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
Expand Down
4 changes: 3 additions & 1 deletion src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TOKEN:
{
< RELATION: "<" | ">" | ">>" | "<<" | "==" | "$+" | "$-" | "$++" | "$--" | "." | ".." | "-" | "--" | ">++" | ">--" | "<++" | "<--" >
| < ALIGNRELN: "@" >
| < IDENTIFIER: (~[" ", "\n", "\r", "(", "/", "|", "@", "!", "#", "%", "&", ")", "=", "?", "[", "]", ">", "<", "~", ".", ",", "$", ":", ";", "{", "}", "+", "-"])+ >
| < IDENTIFIER: (~[" ", "\n", "\r", "(", "/", "|", "@", "!", "#", "%", "&", ")", "=", "?", "[", "]", ">", "<", "~", ".", ",", "$", ":", ";", "{", "}", "+", "-", "*"])+ >
| < NUMBER: ( ["0"-"9"] )+ >
| < EMPTY: "#" >
| < ROOT: "$" >
Expand Down Expand Up @@ -179,6 +179,7 @@ SemgrexPattern Relation() : {
Token relnType = null;
Token numArg = null;
Token numArg2 = null;
Token graphNumber = null;
Token name = null;
Token edgeName = null;
SemgrexPattern node;
Expand All @@ -187,6 +188,7 @@ SemgrexPattern Relation() : {
(
( ( ( (numArg = <IDENTIFIER> ("," numArg2 = <IDENTIFIER>)?)? rel = <RELATION>
(relnType = <IDENTIFIER> | relnType = <REGEX>)?)
(( ("*") graphNumber = <NUMBER> ) )?
(( ("~") name = <IDENTIFIER> ) )?
(( ("=") edgeName = <IDENTIFIER> ) )? )
| (rel = <ALIGNRELN>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface SemgrexParserConstants {
"\"[\"",
"\"]\"",
"\",\"",
"\"*\"",
"\"~\"",
"\"=\"",
"\"{\"",
Expand Down
Loading

0 comments on commit 1ccbebb

Please sign in to comment.