{"record":{"id":"28311fc0b9ec3af2","repo":"stanfordnlp/CoreNLP","slug":"error-cannot-process-tregex-operations-with-no-co","errorCode":null,"errorMessage":"Error: cannot process tregex operations with no constituency tree annotations.  Perhaps need to reinitialize the server with the parse annotator","messagePattern":"Error: cannot process tregex operations with no constituency tree annotations\\.  Perhaps need to reinitialize the server with the parse annotator","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java","lineNumber":1479,"sourceCode":"\n          // Construct the matcher\n          // (get the pattern)\n          if ( ! params.containsKey(\"pattern\")) {\n            respondBadInput(\"Missing required parameter 'pattern'\", httpExchange);\n            return Pair.makePair(\"\", null);\n          }\n          String rawPattern = params.get(\"pattern\");\n\n          // (create the matcher)\n          TregexPattern pattern = TregexPattern.compile(rawPattern);\n\n          // Run Tregex\n          return Pair.makePair(JSONOutputter.JSONWriter.objectToJSON((docWriter) ->\n            docWriter.set(\"sentences\", doc.get(CoreAnnotations.SentencesAnnotation.class).stream().map(sentence -> (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer sentWriter) -> {\n                int sentIndex = sentence.get(CoreAnnotations.SentenceIndexAnnotation.class);\n                Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);\n                if (tree == null) {\n                  throw new IllegalStateException(\"Error: cannot process tregex operations with no constituency tree annotations.  Perhaps need to reinitialize the server with the parse annotator\");\n                }\n                //sentWriter.set(\"tree\", tree.pennString());\n                TregexMatcher matcher = pattern.matcher(tree);\n\n                int i = 0;\n                while (matcher.find()) {\n                  sentWriter.set(Integer.toString(i++), (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer matchWriter) -> {\n                    matchWriter.set(\"sentIndex\", sentIndex);\n                    setTregexOffsets(matchWriter, matcher.getMatch());\n                    matchWriter.set(\"match\", matcher.getMatch().pennString());\n                    matchWriter.set(\"spanString\", matcher.getMatch().spanString());\n                    matchWriter.set(\"namedNodes\", matcher.getNodeNames().stream().map(nodeName -> (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer namedNodeWriter) -> \n                      namedNodeWriter.set(nodeName, (Consumer<JSONOutputter.Writer>) (JSONOutputter.Writer namedNodeSubWriter) -> {\n                        setTregexOffsets(namedNodeSubWriter, matcher.getNode(nodeName));\n                        namedNodeSubWriter.set(\"match\", matcher.getNode(nodeName).pennString());\n                        namedNodeSubWriter.set(\"spanString\", matcher.getNode(nodeName).spanString());\n                      })\n                    ));","sourceCodeStart":1461,"sourceCodeEnd":1497,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java#L1461-L1497","documentation":"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.","triggerScenarios":"POSTing a tregexOperations request to StanfordCoreNLPServer whose pipeline (annotators property) lacks 'parse' (e.g. only tokenize,ssplit,ner), so sentences carry no TreeAnnotation.","commonSituations":"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.","solutions":["Restart the server including the parse annotator: -annotators tokenize,ssplit,parse","Ensure the tregex request's properties do not override annotators to exclude parse","If trees are unavailable, run Tregex offline on pre-parsed tree files instead of via the server"],"exampleFix":"// before\n-annotators \"tokenize,ssplit,ner\"  // then tregex request\n// after\n-annotators \"tokenize,ssplit,parse,ner\"","handlingStrategy":"validation","validationCode":"String annotators = requestProps.getProperty(\"annotators\", \"\");\nif (tregexOperations != null && !annotators.contains(\"parse\")) {\n  throw new IllegalStateException(\"tregex requests require the parse annotator\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  runTregex(props, operations);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"no constituency tree annotations\")) {\n    props.setProperty(\"annotators\", \"tokenize,ssplit,parse\");\n    runTregex(props, operations);\n  } else throw e;\n}","preventionTips":["Always include 'parse' in the annotator list when issuing tregexOperations requests","Check Annotation sentences for TreeCoreAnnotations.TreeAnnotation before querying","Keep a dedicated parse-enabled server instance for tree queries"],"tags":["tregex","server","missing-annotation","constituency-parse"],"backgroundTag":"missing-dependency","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}