stanfordnlp/CoreNLP · error · IllegalArgumentException

Sentiment analysis is not implemented for Chinese

Error message

Sentiment analysis is not implemented for Chinese

What it means

ChineseDocument.runSentiment() throws IllegalArgumentException because no sentiment model is available for Chinese in the stanford.nlp.simple API. Calling Document.sentiment() on a Chinese document always reaches this stub and fails by design.

Solutions

  1. Skip sentiment for ChineseDocument instances (instanceof check before calling).
  2. Use an English (or otherwise supported) document for sentiment analysis.
  3. Wire an external Chinese sentiment model (e.g. a trained classifier) outside the simple API.

Example fix

// before
String s = doc.sentiment();
// after
if (!(doc instanceof ChineseDocument)) {
  String s = doc.sentiment();
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (doc instanceof edu.stanford.nlp.simple.ChineseDocument) skipSentiment = true;

Type guard

boolean supportsSentiment(Document doc) { return !(doc instanceof edu.stanford.nlp.simple.ChineseDocument); }

Try / catch

try {
  doc.sentiment();
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("not implemented")) {
    log.warn("Sentiment unavailable for Chinese, skipping");
  } else throw e;
}

Prevention

When it happens

Trigger: Calling sentiment() on a ChineseDocument, or invoking any operation whose prerequisites route into runSentiment on Chinese text.

Common situations: Multilingual pipelines sentiment-scoring documents in every language; assuming the sentiment annotator works for Chinese as it does for English.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/1b206b8e9fabd93b. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/simple/ChineseDocument.java:105

  /**
   * No lemma annotator for Chinese -- set the lemma to be the word.
   *
   * @see Document#runLemma(Properties)
   */
  @Override
  protected Document runLemma(Properties props) {
    return mockLemma(props);
  }


  /**
   * No sentiment analysis implemented for Chinese.
   *
   * @see Document#runSentiment(Properties)
   */
  @Override
  protected Document runSentiment(Properties props) {
    throw new IllegalArgumentException("Sentiment analysis is not implemented for Chinese");
  }

  /**
   * The Neural Dependency Parser doesn't support Chinese yet, so back off to running the
   * constituency parser instead.
   */
  @Override  // TODO(danqi; from Gabor): remove this method when we have a trained NNDep model
  Document runDepparse(Properties props) {
    return runParse(props);
  }
}

View on GitHub (pinned to 1b7edd19c4)