stanfordnlp/CoreNLP · critical · RuntimeException

: Parser grammar does not exist

Error message

: Parser grammar does not exist

What it means

JointParsingModel.makeParsers builds the PCFG/dependency/bilex parsers from the loaded LexicalizedParser (lp) and throws this RuntimeException if lp is null — i.e. the parser grammar never loaded. This is an initialization-order invariant: the run() pipeline cannot proceed without a grammar, so construction of the parsing machinery is aborted.

Solutions

  1. Verify the parser grammar path passed to the model and confirm the file exists and is readable.
  2. Load the grammar explicitly with LexicalizedParser.loadModel(...) and check for load errors before running.
  3. Re-download the Arabic parser grammar/model files for your CoreNLP version.
  4. Log/inspect why lp stayed null (e.g. a swallowed exception during grammar loading) and fix that first.

Example fix

// before
JointParsingModel model = new JointParsingModel(...);
model.run(words); // throws if grammar missing
// after
LexicalizedParser lp = LexicalizedParser.loadModel(grammarPath); // throws a clear error here
if (lp == null) throw new IllegalStateException("Grammar failed to load: " + grammarPath);
JointParsingModel model = new JointParsingModel(...);
Defensive patterns

Strategy: validation

Validate before calling

// java: confirm the grammar loads before running the joint model
File gf = new File(grammarPath);
if (!gf.isFile() || !gf.canRead()) {
  throw new FileNotFoundException("Parser grammar missing/unreadable: " + grammarPath);
}
LexicalizedParser lp = LexicalizedParser.loadModel(grammarPath); // throws clearly on corrupt model

Try / catch

try {
  model.run(words);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().endsWith("Parser grammar does not exist")) {
    throw new ConfigurationException("Set a valid -parserModel/grammar path and retry");
  } else throw e;
}

Prevention

When it happens

Trigger: Running the parse-segment joint model when the parser grammar failed to load (missing or unreadable grammar file path in the options), so lp remains null when makeParsers is invoked from run().

Common situations: Incorrect -parserModel or grammar path configuration; grammar file not present on the machine (not shipped with the distribution); failed download/corrupt serialized grammar causing silent load failure before makeParsers runs.

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


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/parsesegment/JointParsingModel.java:185

    Timing.tick("done.");

    Extractor<DependencyGrammar> dgExtractor = op.tlpParams.dependencyGrammarExtractor(op, wordIndex, tagIndex);
    DependencyGrammar dg = null;
    if (op.doDep) {
      log.info("Extracting Dependencies...");
      dg = dgExtractor.extract(binaryTrainTrees);
      dg.setLexicon(lex);
      Timing.tick("done.");
    }

    log.info("Done extracting grammars and lexicon.");

    return new LexicalizedParser(lex, bg, ug, dg, stateIndex, wordIndex, tagIndex, op);
  }

  private void makeParsers() {
    if (lp == null)
      throw new RuntimeException(this.getClass().getName() + ": Parser grammar does not exist");

    //a la (Klein and Manning, 2002)
    pparser = new ExhaustivePCFGParser(lp.bg, lp.ug, lp.lex, op, lp.stateIndex, lp.wordIndex, lp.tagIndex);
    dparser = new ExhaustiveDependencyParser(lp.dg, lp.lex, op, lp.wordIndex, lp.tagIndex);
    bparser = new BiLexPCFGParser(new GenericLatticeScorer(), pparser, dparser, lp.bg, lp.ug, lp.dg, lp.lex, op, lp.stateIndex, lp.wordIndex, lp.tagIndex);
  }

  private boolean parse(InputStream inputStream) {
    final LatticeXMLReader reader = new LatticeXMLReader();

    if(!reader.load(inputStream,serInput)) {
      System.err.printf("%s: Error loading input lattice xml from stdin%n", this.getClass().getName());
      return false;
    }

    System.err.printf("%s: Entering main parsing loop...%n", this.getClass().getName());

    int latticeNum = 0;

View on GitHub (pinned to 1b7edd19c4)