stanfordnlp/CoreNLP · error · RuntimeException

Unable to find sentences in

Error message

Unable to find sentences in ${annotation}

What it means

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.

Solutions

  1. Set annotators=tokenize,ssplit,regexner (order matters) so SentencesAnnotation exists before regexner runs.
  2. If calling annotate() manually, run a WordsToSentencesAnnotator first or populate SentencesAnnotation yourself.
  3. Check custom annotate-order/after properties aren't reordering regexner ahead of ssplit.

Example fix

// before
props.setProperty("annotators", "tokenize,regexner");
// after
props.setProperty("annotators", "tokenize,ssplit,regexner");
Defensive patterns

Strategy: validation

Validate before calling

if (!annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
  throw new IllegalStateException("regexner requires sentences; run tokenize,ssplit first");
}

Try / catch

try {
  regexner.annotate(annotation);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Unable to find sentences")) {
    ssplitAnnotator.annotate(annotation);
    regexner.annotate(annotation);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom pipelines listing regexner before ssplit; incremental annotation code that forgets to run earlier stages; test code constructing Annotation objects without SentencesAnnotation.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/RegexNERAnnotator.java:72

  }

  public RegexNERAnnotator(String mapping, boolean ignoreCase, String validPosPattern) {
    this(mapping, ignoreCase, true, validPosPattern, false);
  }

  public RegexNERAnnotator(String mapping, boolean ignoreCase, boolean overwriteMyLabels, String validPosPattern, boolean verbose) {
    classifier = new RegexNERSequenceClassifier(mapping, ignoreCase, overwriteMyLabels, validPosPattern);
    this.verbose = verbose;
  }

  @Override
  public void annotate(Annotation annotation) {
    if (verbose) {
      log.info("Adding RegexNER annotations ... ");
    }

    if (! annotation.containsKey(CoreAnnotations.SentencesAnnotation.class))
      throw new RuntimeException("Unable to find sentences in " + annotation);

    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
      List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
      classifier.classify(tokens);

      for (CoreLabel token : tokens) {
        if (token.get(CoreAnnotations.NamedEntityTagAnnotation.class) == null)
          token.set(CoreAnnotations.NamedEntityTagAnnotation.class, classifier.flags.backgroundSymbol);
      }

      for (int start = 0; start < tokens.size(); start++) {
        CoreLabel token = tokens.get(start);
        String answerType = token.get(CoreAnnotations.AnswerAnnotation.class);
        if (answerType == null) continue;
        String NERType = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);

        int answerEnd = findEndOfAnswerAnnotation(tokens, start);

View on GitHub (pinned to 1b7edd19c4)