{"record":{"id":"8abf3b894a730970","repo":"stanfordnlp/CoreNLP","slug":"unable-to-find-sentences-in","errorCode":null,"errorMessage":"unable to find sentences in: ","messagePattern":"unable to find sentences in: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TrueCaseAnnotator.java","lineNumber":122,"sourceCode":"      log.info(\"Adding true-case 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\n        List<CoreLabel> output = this.trueCaser.classifySentence(tokens);\n\n        for (int i = 0, size = tokens.size(); i < size; i++) {\n          // add the truecaser tag to each token\n          String neTag = output.get(i).get(CoreAnnotations.AnswerAnnotation.class);\n          tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag);\n          setTrueCaseText(tokens.get(i));\n        }\n      }\n    } else {\n      throw new RuntimeException(\"unable to find sentences in: \" + annotation);\n    }\n  }\n\n  private void setTrueCaseText(CoreLabel l) {\n    String trueCase = l.getString(CoreAnnotations.TrueCaseAnnotation.class);\n    String text = l.word();\n    String trueCaseText = text;\n\n    switch (trueCase) {\n      case \"UPPER\":\n        trueCaseText = text.toUpperCase();\n        break;\n      case \"LOWER\":\n        trueCaseText = text.toLowerCase();\n        break;\n      case \"INIT_UPPER\":\n        trueCaseText = Character.toTitleCase(text.charAt(0)) + text.substring(1).toLowerCase();\n        break;","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TrueCaseAnnotator.java#L104-L140","documentation":"TrueCaseAnnotator.annotate requires the input Annotation to contain sentence annotations (SentencesAnnotation), because classification runs per-token over sentence-split text. If no sentences are found, it throws this RuntimeException naming the annotation object.","triggerScenarios":"Calling truecase annotate() directly on an Annotation created from raw text without first running a tokenizer + WordsToSentencesAnnotator (ssplit), e.g. using a pipeline where 'truecase' is requested without 'tokenize,ssplit' preceding it.","commonSituations":"Building a minimal custom pipeline that omits ssplit, running truecase standalone in a test, or clearing/replacing sentences downstream of an earlier stage.","solutions":["Run tokenization and sentence splitting before truecase: include 'tokenize,ssplit' before 'truecase' in the annotators list","If annotating manually, populate CoreAnnotations.SentencesAnnotation on the Annotation before calling annotate()","Use StanfordCoreNLP with requiredAnnotators so prerequisite stages are enforced","Verify an earlier annotator did not remove or fail to produce sentences"],"exampleFix":"// before\nProperties props = new Properties();\nprops.setProperty(\"annotators\", \"truecase\");\n// after\nProperties props = new Properties();\nprops.setProperty(\"annotators\", \"tokenize,ssplit,pos,truecase\");","handlingStrategy":"validation","validationCode":"boolean hasSentences = annotation.get(CoreAnnotations.SentencesAnnotation.class) != null\n    && !annotation.get(CoreAnnotations.SentencesAnnotation.class).isEmpty();\nif (!hasSentences)\n  throw new IllegalStateException(\"Run tokenize,ssplit before truecase\");","typeGuard":null,"tryCatchPattern":"try {\n  trueCaseAnnotator.annotate(annotation);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"unable to find sentences\")) {\n    tokenizeAndSplitSentences(annotation);\n    trueCaseAnnotator.annotate(annotation);\n  } else throw e;\n}","preventionTips":["Always include 'tokenize,ssplit' before 'truecase' in the annotators list","Never call annotate() on a raw Annotation built from text without sentence annotations","Use StanfordCoreNLP's annotator dependency management rather than manual annotator composition","Assert SentencesAnnotation is present in unit tests before annotating"],"tags":["pipeline","truecase","prerequisites"],"backgroundTag":"missing-prerequisite-annotation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}