stanfordnlp/CoreNLP · error · java.lang.RuntimeException
Error parsing to sequence pattern
Error message
Error parsing to sequence pattern
What it means
Env.getSequencePatternExpr resolves a variable to a sequence pattern expression; when the bound object is a String it parses it via TokenSequenceParser.parseSequence, and any parse failure is wrapped in a RuntimeException 'Error parsing <obj> to sequence pattern'.
Solutions
- Inspect the wrapped cause for the parser's error location and fix the sequence syntax
- Bind a SequencePattern/PatternExpr object directly instead of a string
- Validate the expression in a standalone rule file before binding programmatically
Example fix
// before
env.bind("$pat", "{ word:/foo/ } { ");
// after
env.bind("$pat", "{ word:/foo/ }"); Defensive patterns
Strategy: try-catch
Validate before calling
try { new TokenSequenceParser().parseSequence(env, seqString); } catch (Exception e) { throw new IllegalArgumentException("Not valid sequence syntax: " + seqString, e); }
env.bind(name, seqString); Try / catch
try { PatternExpr pe = env.getSequencePatternExpr(name, true); } catch (RuntimeException e) { log.error("Bad sequence string for {}: {}", name, e.getMessage()); throw new IllegalArgumentException("Fix bound sequence: " + name, e.getCause()); } Prevention
- Bind compiled SequencePattern objects instead of strings where feasible
- Validate strings by parsing once at startup
- Keep bracket/operator nesting simple and tested
When it happens
Trigger: env.bind(name, "...") with a string that is not valid TokensRegex sequence syntax, then using the variable in sequence position (getSequencePatternExpr / SeqVar evaluation).
Common situations: Rule strings with grammar errors (bad nesting, unbalanced brackets, invalid operators) bound programmatically; strings intended as literals not quoted/regex-escaped.
Related errors
- Invalid value for key:
- Unknown annotation key:
- Error parsing file:
- Error parsing to node pattern
- Invalid value for type
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/65836bf2d74c7cc3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/Env.java:371
return null;
}
public SequencePattern.PatternExpr getSequencePatternExpr(String name, boolean copy) {
Object obj = variables.get(name);
if (obj != null) {
if (obj instanceof SequencePattern) {
SequencePattern seqPattern = (SequencePattern) obj;
return seqPattern.getPatternExpr();
} else if (obj instanceof SequencePattern.PatternExpr) {
SequencePattern.PatternExpr pe = (SequencePattern.PatternExpr) obj;
return (copy)? pe.copy():pe;
} else if (obj instanceof NodePattern) {
return new SequencePattern.NodePatternExpr( (NodePattern) obj);
} else if (obj instanceof String) {
try {
return parser.parseSequence(this, (String) obj);
} catch (Exception pex) {
throw new RuntimeException("Error parsing " + obj + " to sequence pattern", pex);
}
} else {
throw new Error("Invalid sequence pattern variable class: " + obj.getClass());
}
}
return null;
}
public Object get(String name)
{
return variables.get(name);
}
// Functions for storing temporary thread specific variables
// that are used when running tokensregex
public void push(String name, Object value) {
Map<String,Object> vars = threadLocalVariables.get();View on GitHub (pinned to 1b7edd19c4)