stanfordnlp/CoreNLP · error · ParseException
No named tregex nodes allowed in the scope of negation.
Error message
No named tregex nodes allowed in the scope of negation.
What it means
Tregex forbids declaring a named node (a variable binding) inside the scope of a negation, because a binding created in a negated subexpression can never be reliably bound (the subexpression is required to fail). The parser throws ParseException when it sees =name while underNegation is true.
Solutions
- Remove the =name binding from inside the negation
- Restructure the query: negate a subpattern that references an externally named node instead
- Match positively, then filter results in Java code after matching
Example fix
// before
String pattern = "NP < !(NNS=${name})";
// after
String pattern = "NP < !NNS"; // filter/extract in code instead Defensive patterns
Strategy: validation
Validate before calling
// reject named nodes inside negation before compiling
if (pattern.matches(".*!.*=\\w+.*")) throw new IllegalArgumentException("named node inside negation: " + pattern); Try / catch
try { TregexPattern.compile(pattern); } catch (ParseException e) { /* named node under negation; rewrite query */ } Prevention
- Never use =name on nodes inside ! or negation scope
- Capture positively and filter results in code instead
- Learn tregex negation scoping rules before adding bindings
When it happens
Trigger: Compiling a pattern like "!A=${name}" or any named node appearing within !(...) negation scope.
Common situations: Users trying to capture what did NOT match; converting positive queries to negated ones without removing capture names; misunderstanding that negated nodes cannot produce bindings.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Unrecognized simple relation
- Unrecognized compound relation
- Unknown multi relation
- Variable has been declared twice, which makes no sense
- Variable was referenced before it was declared
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/39c9cb5840690e43.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/tregex/TregexParser.java:258
break label_2;
}
jj_consume_token(19);
groupNum = jj_consume_token(NUMBER);
jj_consume_token(20);
groupVar = jj_consume_token(IDENTIFIER);
varGroups.add(new Pair<Integer,String>(Integer.parseInt(groupNum.image),groupVar.image));
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 21:{
jj_consume_token(21);
name = jj_consume_token(IDENTIFIER);
if (knownVariables.contains(name.image)) {
{if (true) throw new ParseException("Variable " + name.image + " has been declared twice, which makes no sense");}
} else {
knownVariables.add(name.image);
}
if (underNegation)
{if (true) throw new ParseException("No named tregex nodes allowed in the scope of negation.");}
break;
}
default:
jj_la1[8] = jj_gen;
;
}
break;
}
case 22:{
jj_consume_token(22);
linkedName = jj_consume_token(IDENTIFIER);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case 21:{
jj_consume_token(21);
name = jj_consume_token(IDENTIFIER);
break;
}
default:View on GitHub (pinned to 1b7edd19c4)