stanfordnlp/CoreNLP · error · UnsupportedOperationException
Can only parse raw text if a tagger is specified, as the…
Error message
Can only parse raw text if a tagger is specified, as the ShiftReduceParser cannot produce its own tags
What it means
ShiftReduceParser.parse(String) accepts raw (untagged) text, but the parser cannot POS-tag sentences itself; it requires pre-tagged input. If the test option preTag is false — meaning no tagger was configured — calling the String overload cannot proceed and throws UnsupportedOperationException.
Solutions
- Tag the sentence yourself and call parse(List<? extends HasWord>) with CoreLabels carrying tags
- Load/parser-config with a tagger so preTag is enabled (e.g. specify -testOptions preTag with a tagger serialized path)
- Use a parser model serialized together with its tagger
Example fix
// before
Tree t = parser.parse("The dog barked");
// after
List<CoreLabel> tagged = tokenizerFactory.getTokenizer(new StringReader("The dog barked")).tokenize();
// ... set tags via a tagger ...
Tree t = parser.parse(tagged); Defensive patterns
Strategy: type-guard
Validate before calling
if (!parser.getOp().testOptions.preTag) {
throw new IllegalStateException("Supply tagged List<HasWord> instead of raw text");
} Try / catch
try {
return parser.parse(rawSentence);
} catch (UnsupportedOperationException e) {
return parser.parse(tagger.apply(tokenize(rawSentence)));
} Prevention
- Always call the List<HasWord> overload unless the model bundles a tagger
- Check testOptions.preTag at pipeline startup
- Bundle the tagger with the serialized parser model
When it happens
Trigger: Calling parser.parse("some raw sentence") on a parser model loaded without a tagger (op.testOptions.preTag == false).
Common situations: Loading a serialized ShiftReduceParser model trained without a POS tagger and passing plain text; upgrading models or switching from a parser+tagger bundle to a bare parser while keeping raw-text call sites.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- ChineseCharacterBasedLexicon has no rule iterator!
- : Does not support parse operation.
- Sorry, but parsers with rerankers cannot be saved to text…
- This evaluator only works for the ShiftReduceParser
- This evaluator only works for the ShiftReduceParser
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8c2c66a2f95033e9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/shiftreduce/ShiftReduceParser.java:176
/** Return the Set of POS tags used in the model. */
public Set<String> tagSet() {
return model.tagSet();
}
@Override
public boolean requiresTags() {
return true;
}
@Override
public ParserQuery parserQuery() {
return new ShiftReduceParserQuery(this);
}
@Override
public Tree parse(String sentence) {
if (!getOp().testOptions.preTag) {
throw new UnsupportedOperationException("Can only parse raw text if a tagger is specified, as the ShiftReduceParser cannot produce its own tags");
}
return super.parse(sentence);
}
@Override
public Tree parse(List<? extends HasWord> sentence) {
ShiftReduceParserQuery pq = new ShiftReduceParserQuery(this);
if (pq.parse(sentence)) {
return pq.getBestParse();
}
return ParserUtils.xTree(sentence);
}
@Override
public Tree parseTree(List<? extends HasWord> sentence) {
ShiftReduceParserQuery pq = new ShiftReduceParserQuery(this);
if (pq.parse(sentence)) {
return pq.getBestParse();View on GitHub (pinned to 1b7edd19c4)