stanfordnlp/CoreNLP · error · java.lang.Error
Unknown sequence pattern variable
Error message
Unknown sequence pattern variable
What it means
SeqVar resolves a REGEXVAR token (a '$name' reference) to a previously registered SequencePattern.PatternExpr in the parse environment. If env.getSequencePatternExpr(name.image, true) returns null, the parser throws 'Unknown sequence pattern variable <name>' because the referenced pattern variable was never defined in the environment.
Solutions
- Define the referenced variable before use, e.g. with a rule like 'pattern = ( ... )' or env.bind(name, patternExpr) in code.
- Check exact name and case match between the definition and the $reference.
- Load all variable-defining rule files into the same Env before parsing dependent rules.
- Log env contents (or iterate bound names) to confirm which sequence pattern variables exist.
Example fix
// before
String rule = "$DATE"; // never defined
// after
env.bind("DATE", datePattern); // or add: $DATE = ( [ { tag:/DATE/ } ] )\n... $DATE ... Defensive patterns
Strategy: validation
Validate before calling
// Confirm all $refs used in a rule are defined in the Env first
Set<String> defined = env variable names; // collect via your binding registry
java.util.regex.Matcher m = java.util.regex.Pattern.compile("\\$([A-Za-z_]\\w*)").matcher(ruleText);
while (m.find()) {
if (!defined.contains(m.group(1))) throw new IllegalStateException("Undefined variable: " + m.group(1));
} Try / catch
try {
return parser.parsePattern(env, ruleText);
} catch (Error e) {
if (e.getMessage() != null && e.getMessage().startsWith("Unknown sequence pattern variable")) {
throw new IllegalArgumentException(e.getMessage() + " - define it via a pattern rule or env.bind() first", e);
}
throw e;
} Prevention
- Bind all sequence pattern variables before parsing dependent rules.
- Keep variable definitions in the same rule file, above their uses.
- Match variable names exactly (case-sensitive).
When it happens
Trigger: Parsing a TokensRegex sequence pattern whose text references $VarName, but no pattern of that name was registered in the Env (e.g. via env.bind or sequence pattern definitions) before parsing.
Common situations: Rule files where the variable definition rule was removed, renamed, or where variables are defined in a separate file not loaded into the same environment; also case-sensitivity mismatches between definition and reference.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Unknown sequence pattern variable
- Attribute match already defined
- Attribute already defined
- Field already defined:
- Attribute match already defined:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d4e133c1b866f89d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java:1287
jj_consume_token(32);
break;
}
default:
jj_la1[40] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
{if ("" != null) return node;}
throw new Error("Missing return statement in function");
}
final public SequencePattern.PatternExpr SeqVar(Env env) throws ParseException {SequencePattern.PatternExpr expr;
Token name;
name = jj_consume_token(REGEXVAR);
expr = env.getSequencePatternExpr(name.image, true);
if (expr == null) {
{if (true) throw new Error("Unknown sequence pattern variable " + name.image);}
}
{if ("" != null) return expr;}
throw new Error("Missing return statement in function");
}
final public SequencePattern.PatternExpr SeqBackRef(Env env) throws ParseException {Token name;
name = jj_consume_token(BACKREF);
int v = Integer.parseInt(name.image.substring(1));
{if ("" != null) return new SequencePattern.BackRefPatternExpr(CoreMapNodePattern.TEXT_ATTR_EQUAL_CHECKER, v);}
throw new Error("Missing return statement in function");
}
final public NodePattern Node(Env env) throws ParseException {NodePattern node;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 31:{
node = BracketedNode(env);
break;
}View on GitHub (pinned to 1b7edd19c4)