{"record":{"id":"542710d9b431cf21","repo":"stanfordnlp/CoreNLP","slug":"unable-to-find-sentences-in-annotation-542710","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/NumberAnnotator.java","lineNumber":86,"sourceCode":"  public void annotate(Annotation annotation) {\n    if (VERBOSE) {\n      log.info(\"Adding number annotation ... \");\n    }\n\n    if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {\n      // classify tokens for each sentence\n      for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {\n        List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);\n        doOneSentenceNew(tokens, annotation, sentence);\n      }\n      if (VERBOSE) {\n        log.info(\"done. Output: \" + annotation.get(CoreAnnotations.SentencesAnnotation.class));\n      }\n    } else if (annotation.containsKey(CoreAnnotations.TokensAnnotation.class)) {\n      List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class);\n      doOneSentenceNew(tokens, annotation, null);\n    } else {\n      throw new RuntimeException(\"unable to find sentences in: \" + annotation);\n    }\n  }\n\n  private void doOneSentenceNew(List<CoreLabel> words, Annotation doc, CoreMap sentence) {\n    List<CoreLabel> newWords = NumberSequenceClassifier.copyTokens(words, sentence);\n\n    nsc.classifyWithGlobalInformation(newWords, doc, sentence);\n\n    Iterator<? extends CoreLabel> newFLIter = newWords.iterator();\n    for (CoreLabel origWord : words) {\n      CoreLabel newWord = newFLIter.next();\n      String before = origWord.ner();\n      String newGuess = newWord.get(CoreAnnotations.AnswerAnnotation.class);\n      // log.info(origWord.word());\n      // log.info(origWord.ner());\n      if (VERBOSE)\n        log.info(newWord);\n      // log.info(\"-------------------------------------\");","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/NumberAnnotator.java#L68-L104","documentation":"An IllegalStateException precondition check in NumberAnnotator.annotate: the input Annotation lacks the SentencesAnnotation key, meaning sentence splitting must run before the number annotator; the annotation object is at fault.","triggerScenarios":"Invoking NumberAnnotator.annotate() on an Annotation lacking both SentencesAnnotation and TokensAnnotation, i.e. the text was never tokenized or sentence-split.","commonSituations":"Running the 'number' annotator standalone without prerequisite annotators; manually constructing an Annotation from a String without running tokenize/ssplit first.","solutions":["Include 'tokenize,ssplit' before 'number' in the annotators property","Ensure TokensAnnotation is populated (run a tokenizer) before invoking the annotator","Use the full StanfordCoreNLP pipeline rather than instantiating NumberAnnotator directly"],"exampleFix":"// before\nprops.setProperty(\"annotators\", \"number\");\n// after\nprops.setProperty(\"annotators\", \"tokenize,ssplit,number\");","handlingStrategy":"validation","validationCode":"if (!annotation.containsKey(CoreAnnotations.TokensAnnotation.class) && !annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { pipeline.annotate(annotation); }","typeGuard":null,"tryCatchPattern":"try { numberAnnotator.annotate(annotation); } catch (RuntimeException e) { if (e.getMessage().contains(\"unable to find sentences\")) { tokenizeAndSplit(annotation); numberAnnotator.annotate(annotation); } else throw e; }","preventionTips":["Run the full pipeline; never instantiate NumberAnnotator standalone on untokenized text","Check annotation.containsKey(TokensAnnotation.class) before calling specialized annotators"],"tags":["java","nlp","pipeline","missing-annotation"],"backgroundTag":"missing-required-config-field","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"}