stanfordnlp/CoreNLP · error · IllegalArgumentException

Sentiment analysis is not implemented for Arabic

Error message

Sentiment analysis is not implemented for Arabic

What it means

ArabicDocument (stanford.nlp.simple) does not ship sentiment analysis support for Arabic. Calling runSentiment() — triggered by Document.sentiment(...) on an Arabic document — throws IllegalArgumentException by design, since no Arabic sentiment model is wired into the simple pipeline.

Solutions

  1. Do not call sentiment() on ArabicDocument; skip sentiment for Arabic documents (check the document type first).
  2. Use an English (or other supported-language) document for sentiment analysis.
  3. Integrate an external Arabic sentiment tool and call it directly instead of the CoreNLP simple API.

Example fix

// before
doc.sentiment();
// after
if (!(doc instanceof ArabicDocument)) {
  doc.sentiment();
}
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Creating a Document with the Arabic backend/language and calling sentiment() or any pipeline step that internally calls runSentiment(props).

Common situations: Running multilingual pipelines where the same code path sentiment-analyzes documents of all languages; assuming Arabic support parity with English in Stanford CoreNLP simple API.

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


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

Appendix: source

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

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


  /**
   * No lemma annotator for Arabic -- 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 Arabic");
  }


  @Override
  protected Document runDepparse(Properties props) {
    throw new IllegalArgumentException("Dependency parsing is not implemented for Arabic");
  }

  @Override
  protected Document runNER(Properties props) {
    throw new IllegalArgumentException("NER is not implemented for Arabic");
  }


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

View on GitHub (pinned to 1b7edd19c4)