stanfordnlp/CoreNLP · error · IllegalStateException

Error: cannot process tregex operations with no…

Error message

Error: cannot process tregex operations with no constituency tree annotations.  Perhaps need to reinitialize the server with the parse annotator

What it means

The server's tregex operation endpoint matches Tregex patterns against each sentence's constituency tree (TreeAnnotation). If the pipeline used to build the document did not include a parser/constituency annotator, the tree is null and an IllegalStateException is thrown telling you to reinitialize the server.

Solutions

  1. Restart the server including the parse annotator: -annotators tokenize,ssplit,parse
  2. Ensure the tregex request's properties do not override annotators to exclude parse
  3. If trees are unavailable, run Tregex offline on pre-parsed tree files instead of via the server

Example fix

// before
-annotators "tokenize,ssplit,ner"  // then tregex request
// after
-annotators "tokenize,ssplit,parse,ner"
Defensive patterns

Strategy: validation

Validate before calling

String annotators = requestProps.getProperty("annotators", "");
if (tregexOperations != null && !annotators.contains("parse")) {
  throw new IllegalStateException("tregex requests require the parse annotator");
}

Try / catch

try {
  runTregex(props, operations);
} catch (IllegalStateException e) {
  if (e.getMessage().contains("no constituency tree annotations")) {
    props.setProperty("annotators", "tokenize,ssplit,parse");
    runTregex(props, operations);
  } else throw e;
}

Prevention

When it happens

Trigger: POSTing a tregexOperations request to StanfordCoreNLPServer whose pipeline (annotators property) lacks 'parse' (e.g. only tokenize,ssplit,ner), so sentences carry no TreeAnnotation.

Common situations: Reusing a lightweight server for tregex queries; server started with default annotators but client overrides annotators to exclude parse; memory-conscious setups that dropped the parser.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java:1479

          // Construct the matcher
          // (get the pattern)
          if ( ! params.containsKey("pattern")) {
            respondBadInput("Missing required parameter 'pattern'", httpExchange);
            return Pair.makePair("", null);
          }
          String rawPattern = params.get("pattern");

          // (create the matcher)
          TregexPattern pattern = TregexPattern.compile(rawPattern);

          // Run Tregex
          return Pair.makePair(JSONOutputter.JSONWriter.objectToJSON((docWriter) ->
            docWriter.set("sentences", doc.get(CoreAnnotations.SentencesAnnotation.class).stream().map(sentence -> (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer sentWriter) -> {
                int sentIndex = sentence.get(CoreAnnotations.SentenceIndexAnnotation.class);
                Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
                if (tree == null) {
                  throw new IllegalStateException("Error: cannot process tregex operations with no constituency tree annotations.  Perhaps need to reinitialize the server with the parse annotator");
                }
                //sentWriter.set("tree", tree.pennString());
                TregexMatcher matcher = pattern.matcher(tree);

                int i = 0;
                while (matcher.find()) {
                  sentWriter.set(Integer.toString(i++), (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer matchWriter) -> {
                    matchWriter.set("sentIndex", sentIndex);
                    setTregexOffsets(matchWriter, matcher.getMatch());
                    matchWriter.set("match", matcher.getMatch().pennString());
                    matchWriter.set("spanString", matcher.getMatch().spanString());
                    matchWriter.set("namedNodes", matcher.getNodeNames().stream().map(nodeName -> (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer namedNodeWriter) -> 
                      namedNodeWriter.set(nodeName, (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer namedNodeSubWriter) -> {
                        setTregexOffsets(namedNodeSubWriter, matcher.getNode(nodeName));
                        namedNodeSubWriter.set("match", matcher.getNode(nodeName).pennString());
                        namedNodeSubWriter.set("spanString", matcher.getNode(nodeName).spanString());
                      })
                    ));

View on GitHub (pinned to 1b7edd19c4)