stanfordnlp/CoreNLP · error · UnsupportedOperationException
Not implemented for this class.
Error message
Not implemented for this class.
What it means
AbstractSequenceClassifier.printProbsDocument is a stub: the base class does not provide per-document probability output, so calling it always throws UnsupportedOperationException. Only subclasses that override it support this operation.
Solutions
- Check the concrete class (classifier.getClass()) and whether it overrides printProbsDocument
- Use an alternative API such as classify with a ProbabilityDocumentReaderAndWriter or the classification() method to get scores
- Override printProbsDocument in your subclass
- Upgrade the library version if a newer one implements it
Example fix
// before
Triple<Counter<Integer>, Counter<Integer>, TwoDimensionalCounter<Integer,String>> p = classifier.printProbsDocument(doc);
// after
if (classifier.getClass().equals(AbstractSequenceClassifier.class)) {
// use classify(doc) and inspect labels/scores instead
} else {
var p = classifier.printProbsDocument(doc);
} Defensive patterns
Strategy: try-catch
Type guard
boolean supported = !(classifier.getClass() == AbstractSequenceClassifier.class); // only call printProbsDocument when a subclass overrides it
Try / catch
try { probs = classifier.printProbsDocument(doc); }
catch (UnsupportedOperationException e) { probs = fallbackScoring(doc); } Prevention
- Check for an override in the concrete class before calling stub methods
- Prefer documented alternatives (classification(), classify()) for scores
- Read the Javadoc: base-class stubs mean subclass support only
When it happens
Trigger: Calling classifier.printProbsDocument(document) on a classifier instance whose class (e.g. a generic ColumnDocumentClassifierAndWriter-less subclass) does not override printProbsDocument.
Common situations: Calling the method on a classifier loaded from a serialized model whose runtime class lacks the override; expecting base-class functionality that is documented as subclass-provided.
Related errors
- LogPrior.getSigmaSquaredM is undefined for any prior but…
- If you want to ask for the probability, you must train a…
- Predict not implemented for max margin
- CRFLogConditionalObjectiveFloatFunction is not clique…
- : Does not support parse operation.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d18e7f0635e5f583.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java:1046
}
public void classifyStdin() throws IOException {
classifyStdin(plainTextReaderAndWriter());
}
public void classifyStdin(DocumentReaderAndWriter<IN> readerWriter) throws IOException {
BufferedReader is = IOUtils.readerFromStdin(flags.inputEncoding);
for (String line; (line = is.readLine()) != null; ) {
Collection<List<IN>> documents = makeObjectBankFromString(line, readerWriter);
if (flags.keepEmptySentences && documents.isEmpty()) {
documents = Collections.<List<IN>>singletonList(Collections.<IN>emptyList());
}
classifyAndWriteAnswers(documents, readerWriter, false);
}
}
public Triple<Counter<Integer>, Counter<Integer>, TwoDimensionalCounter<Integer,String>> printProbsDocument(List<IN> document) {
throw new UnsupportedOperationException("Not implemented for this class.");
}
/** Does nothing by default. Subclasses can override if necessary. */
public void dumpFeatures(Collection<List<IN>> documents) {}
/**
* Load a text file, run the classifier on it, and then print the answers to
* stdout (with timing to stderr). This uses the value of flags.plainTextDocumentReaderAndWriter
* to determine how to read the textFile format. By default this gives
* edu.stanford.nlp.sequences.PlainTextDocumentReaderAndWriter.
* <i>Note:</i> This means that it works right for
* a plain textFile (and not a tab-separated columns test file).
*
* @param textFile The file to test on.
*/
public void classifyAndWriteAnswers(String textFile)
throws IOException {
classifyAndWriteAnswers(textFile, plainTextReaderAndWriter(), false);View on GitHub (pinned to 1b7edd19c4)