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

  1. Check the concrete class (classifier.getClass()) and whether it overrides printProbsDocument
  2. Use an alternative API such as classify with a ProbabilityDocumentReaderAndWriter or the classification() method to get scores
  3. Override printProbsDocument in your subclass
  4. 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

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


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)