stanfordnlp/CoreNLP · error · RuntimeException
unable to find sentences in:
Error message
unable to find sentences in:
What it means
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.
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
Example fix
// before
Properties props = new Properties();
props.setProperty("annotators", "truecase");
// after
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,truecase"); Defensive patterns
Strategy: validation
Validate before calling
boolean hasSentences = annotation.get(CoreAnnotations.SentencesAnnotation.class) != null
&& !annotation.get(CoreAnnotations.SentencesAnnotation.class).isEmpty();
if (!hasSentences)
throw new IllegalStateException("Run tokenize,ssplit before truecase"); Try / catch
try {
trueCaseAnnotator.annotate(annotation);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("unable to find sentences")) {
tokenizeAndSplitSentences(annotation);
trueCaseAnnotator.annotate(annotation);
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Building a minimal custom pipeline that omits ssplit, running truecase standalone in a test, or clearing/replacing sentences downstream of an earlier stage.
Related errors
- annotator " " requires annotation " ". The usual…
- Cannot run Natural Logic forward entailment without…
- Cannot run OpenIE without a parse tree!
- DocumentIterator exhausted.
- Error annotating
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8abf3b894a730970.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/TrueCaseAnnotator.java:122
log.info("Adding true-case annotation...");
}
if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
// classify tokens for each sentence
for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
List<CoreLabel> output = this.trueCaser.classifySentence(tokens);
for (int i = 0, size = tokens.size(); i < size; i++) {
// add the truecaser tag to each token
String neTag = output.get(i).get(CoreAnnotations.AnswerAnnotation.class);
tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag);
setTrueCaseText(tokens.get(i));
}
}
} else {
throw new RuntimeException("unable to find sentences in: " + annotation);
}
}
private void setTrueCaseText(CoreLabel l) {
String trueCase = l.getString(CoreAnnotations.TrueCaseAnnotation.class);
String text = l.word();
String trueCaseText = text;
switch (trueCase) {
case "UPPER":
trueCaseText = text.toUpperCase();
break;
case "LOWER":
trueCaseText = text.toLowerCase();
break;
case "INIT_UPPER":
trueCaseText = Character.toTitleCase(text.charAt(0)) + text.substring(1).toLowerCase();
break;View on GitHub (pinned to 1b7edd19c4)