stanfordnlp/CoreNLP · error · SemgrexParseException

Use of & in semgrex patterns is now illegal. It is…

Error message

Use of & in semgrex patterns is now illegal.  It is equivalent to the same expression without the &.  Offending expression: 

What it means

The semgrex grammar's Root production throws SemgrexParseException when the parsed expression used '&' (deprecatedAmp). '&' in semgrex used to behave identically to plain juxtaposition (conjunction), so it was deprecated and is now illegal to avoid confusion with intended boolean semantics.

Solutions

  1. Remove '&' — replace 'foo & bar' with 'foo bar' (whitespace already means conjunction)
  2. Rewrite patterns like '< [foo & bar]' as 'zzz > foo > bar' or use named-edge forms
  3. Audit legacy semgrex patterns and strip all '&' occurrences before upgrading CoreNLP

Example fix

// before
[{tag:NN} & {word:dog}]
// after
[{tag:NN} {word:dog}]
Defensive patterns

Strategy: validation

Validate before calling

if (pattern.contains("&")) throw new IllegalArgumentException("'&' is illegal in semgrex; use whitespace for conjunction: " + pattern);

Try / catch

try { SemgrexPattern.compile(pattern); } catch (SemgrexParseException e) { log.error(e.getMessage()); }

Prevention

When it happens

Trigger: Parsing a semgrex pattern containing a '&' between node/conjunction elements (e.g. '[foo & bar]' or '< [foo & bar]'), which sets deprecatedAmp during tokenization and triggers the exception at the end of Root.

Common situations: Users familiar with boolean-query syntaxes (or Tregex conventions) writing '&' for conjunction in semgrex; older patterns written before '&' was deprecated now failing after a CoreNLP upgrade.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/2f37d7cecb7c9020. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.java:98

        default:
          jj_la1[0] = jj_gen;
          break label_1;
        }
        jj_consume_token(10);
        node = SubNode(GraphRelation.ITERATOR);
children.add(node);
      }
      break;
      }
    default:
      jj_la1[1] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
if (children.size() > 1)
        node = new CoordinationPattern(true, children, true, true);
      if (deprecatedAmp) {
        {if (true) throw new SemgrexParseException("Use of & in semgrex patterns is now illegal.  It is equivalent to the same expression without the &.  Offending expression: " + startToken);}
      }
      if (deprecatedNodeConj) {
        {if (true) throw new SemgrexParseException("Use of node conjugation (expressions such as '< [foo bar]' or '< [foo & bar]') is now illegal.  The issue is that expressions such as '[foo bar] < zzz' may intuitively mean that foo < zzz, bar < zzz, zzz the same for both cases, but that is not the way the parser interpreted this expression.  Changing the functionality might break existing expressions, and anyway this can be rewritten in various ways such as 'zzz > foo > bar' or 'foo < zzz=a : bar < zzz=a'.  Offending expression: " + startToken);}
      }
    switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
    case 11:{
      jj_consume_token(11);
      jj_consume_token(UNIQ);
uniqKeys = new ArrayList<>();
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
        case UNIQ:
        case IDENTIFIER:{
          ;
          break;
          }
        default:

View on GitHub (pinned to 1b7edd19c4)