stanfordnlp/CoreNLP · error · IllegalArgumentException

Sentiment analysis is not implemented for French

Error message

Sentiment analysis is not implemented for French

What it means

FrenchDocument.runSentiment() throws IllegalArgumentException because sentiment analysis is not implemented for French in the stanford.nlp.simple API. Calling Document.sentiment() on a French document always reaches this stub and fails by design.

Solutions

  1. Skip sentiment for FrenchDocument instances (instanceof check before calling).
  2. Use an English (or otherwise supported) document for sentiment analysis.
  3. Integrate an external French sentiment model outside the CoreNLP simple API.

Example fix

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

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling sentiment() on a FrenchDocument, or a pipeline step whose prerequisites route into runSentiment on French text.

Common situations: Multilingual pipelines sentiment-scoring all documents; assuming French has parity with English sentiment support in CoreNLP's simple API.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/simple/FrenchDocument.java:83

  protected FrenchDocument(Properties props, String text) {
    super(props, text);
  }


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


  @Override
  protected Document runSentiment(Properties props) {
    throw new IllegalArgumentException("Sentiment analysis is not implemented for French");
  }

  @Override
  public Map<Integer, CorefChain> coref(Properties props) {
    throw new IllegalArgumentException("Coreference is not implemented for French");
  }

}

View on GitHub (pinned to 1b7edd19c4)