stanfordnlp/CoreNLP · error · RuntimeException

Grammar format error. Expected bar in state name:

Error message

Grammar format error. Expected bar in state name: 

What it means

getTopCategoryOfSyntheticState parses synthetic (machine-generated) grammar state names, which must have the form '@<topcat>|<rest>'. If the string starts with '@' but contains no '|' separator, the state name is malformed and this RuntimeException identifies the offending name.

Solutions

  1. Regenerate or re-save the grammar with the same parser version that created it.
  2. Inspect the offending state name and fix the missing '|' separator if the grammar file was hand-edited.
  3. Skip compaction (compactGrammar = 0) when processing grammars from incompatible sources.
Defensive patterns

Strategy: validation

Validate before calling

if (state.startsWith("@") && !state.contains("|"))
    throw new IllegalArgumentException("Malformed synthetic state: " + state);

Try / catch

try { compact(grammar); } catch (RuntimeException e) { log.error("Grammar format mismatch: " + e.getMessage()); }

Prevention

When it happens

Trigger: Deserializing or compacting a grammar whose split-state names (from splitTraining or a serialized grammar file) lack the expected '|', e.g. when reading a grammar produced by a different/older format.

Common situations: Loading a text- or serialized-format grammar written by another version of the parser, or hand-edited grammar files, into GrammarCompactor's transducer-graph conversion.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/GrammarCompactor.java:211

  }

  protected static TransducerGraph getGraphFromMap(Map<String, TransducerGraph> m, String o) {
    TransducerGraph graph = m.get(o);
    if (graph == null) {
      graph = new TransducerGraph();
      graph.setEndNode(o);
      m.put(o, graph);
    }
    return graph;
  }

  protected static String getTopCategoryOfSyntheticState(String s) {
    if (s.charAt(0) != '@') {
      return null;
    }
    int bar = s.indexOf('|');
    if (bar < 0) {
      throw new RuntimeException("Grammar format error. Expected bar in state name: " + s);
    }
    String topcat = s.substring(1, bar);
    return topcat;
  }

  protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) {
    String parentString = stateIndex.get(rule.parent);
    String childString = stateIndex.get(rule.child);
    if (isSyntheticState(parentString)) {
      String topcat = getTopCategoryOfSyntheticState(parentString);
      TransducerGraph graph = getGraphFromMap(graphs, topcat);
      Double output = Double.valueOf(smartNegate(rule.score()));
      graph.addArc(graph.getStartNode(), parentString, childString, output);
      return true;
    } else if (isSyntheticState(childString)) {
      // need to add Arc from synthetic state to endState
      TransducerGraph graph = getGraphFromMap(graphs, parentString);
      Double output = Double.valueOf(smartNegate(rule.score()));

View on GitHub (pinned to 1b7edd19c4)