{"record":{"id":"f82da8e156a5ea3f","repo":"stanfordnlp/CoreNLP","slug":"unable-to-find-sentences-in-annotation-f82da8","errorCode":null,"errorMessage":"Unable to find sentences in ${annotation}","messagePattern":"Unable to find sentences in (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/RegexNERAnnotator.java","lineNumber":72,"sourceCode":"  }\n\n  public RegexNERAnnotator(String mapping, boolean ignoreCase, String validPosPattern) {\n    this(mapping, ignoreCase, true, validPosPattern, false);\n  }\n\n  public RegexNERAnnotator(String mapping, boolean ignoreCase, boolean overwriteMyLabels, String validPosPattern, boolean verbose) {\n    classifier = new RegexNERSequenceClassifier(mapping, ignoreCase, overwriteMyLabels, validPosPattern);\n    this.verbose = verbose;\n  }\n\n  @Override\n  public void annotate(Annotation annotation) {\n    if (verbose) {\n      log.info(\"Adding RegexNER annotations ... \");\n    }\n\n    if (! annotation.containsKey(CoreAnnotations.SentencesAnnotation.class))\n      throw new RuntimeException(\"Unable to find sentences in \" + annotation);\n\n    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);\n    for (CoreMap sentence : sentences) {\n      List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);\n      classifier.classify(tokens);\n\n      for (CoreLabel token : tokens) {\n        if (token.get(CoreAnnotations.NamedEntityTagAnnotation.class) == null)\n          token.set(CoreAnnotations.NamedEntityTagAnnotation.class, classifier.flags.backgroundSymbol);\n      }\n\n      for (int start = 0; start < tokens.size(); start++) {\n        CoreLabel token = tokens.get(start);\n        String answerType = token.get(CoreAnnotations.AnswerAnnotation.class);\n        if (answerType == null) continue;\n        String NERType = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);\n\n        int answerEnd = findEndOfAnswerAnnotation(tokens, start);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/RegexNERAnnotator.java#L54-L90","documentation":"RegexNERAnnotator.annotate requires the Annotation to already contain CoreAnnotations.SentencesAnnotation. If the sentence key is absent there is nothing to run the NER regex classifier over, so it throws a RuntimeException asking the caller to run sentence splitting first.","triggerScenarios":"Running the 'regexner' annotator on an Annotation that never went through 'ssplit' (and 'tokenize'), or calling annotate() directly on a fresh Annotation with only raw text.","commonSituations":"Custom pipelines listing regexner before ssplit; incremental annotation code that forgets to run earlier stages; test code constructing Annotation objects without SentencesAnnotation.","solutions":["Set annotators=tokenize,ssplit,regexner (order matters) so SentencesAnnotation exists before regexner runs.","If calling annotate() manually, run a WordsToSentencesAnnotator first or populate SentencesAnnotation yourself.","Check custom annotate-order/after properties aren't reordering regexner ahead of ssplit."],"exampleFix":"// before\nprops.setProperty(\"annotators\", \"tokenize,regexner\");\n// after\nprops.setProperty(\"annotators\", \"tokenize,ssplit,regexner\");","handlingStrategy":"validation","validationCode":"if (!annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {\n  throw new IllegalStateException(\"regexner requires sentences; run tokenize,ssplit first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  regexner.annotate(annotation);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unable to find sentences\")) {\n    ssplitAnnotator.annotate(annotation);\n    regexner.annotate(annotation);\n  } else throw e;\n}","preventionTips":["Order the pipeline as tokenize,ssplit,regexner.","Don't call RegexNERAnnotator.annotate() on raw Annotations in tests; run the full pipeline.","Check custom 'after'/annotate-order settings don't move regexner before ssplit."],"tags":["corenlp","pipeline","missing-annotation","ner"],"backgroundTag":"missing-required-argument","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"}