stanfordnlp/CoreNLP · error · IllegalArgumentException

Sentiment analysis is not implemented for Spanish

Error message

Sentiment analysis is not implemented for Spanish

What it means

SpanishDocument.runSentiment is an explicit stub: the Stanford CoreNLP Spanish pipeline has no sentiment model, so calling any sentiment API on a Spanish document throws IllegalArgumentException. This is an intentional unsupported-feature signal, not a bug.

Solutions

  1. Do not call sentiment analysis on SpanishDocument; skip it for Spanish text
  2. Use an English Document/model for sentiment if acceptable, or apply a language-appropriate sentiment tool
  3. Wrap the call in a language check: only run sentiment when document language supports it
  4. Contribute/plug in a Spanish sentiment annotator via a custom Document subclass

Example fix

// before
Document d = new SpanishDocument(text);
d.sentiment(); // throws
// after
if (!(d instanceof SpanishDocument)) {
  d.sentiment();
}
Defensive patterns

Strategy: fallback

Validate before calling

if (doc instanceof SpanishDocument) { /* skip sentiment */ }

Type guard

boolean supportsSentiment(Document d) { return !(d instanceof SpanishDocument); }

Try / catch

try {
  doc.sentiment();
} catch (IllegalArgumentException e) {
  // mark sentiment unsupported for this language
}

Prevention

When it happens

Trigger: Calling sentiment(), runSentiment(props), or Document APIs that trigger the sentiment annotator on a SpanishDocument instance.

Common situations: Generic pipeline code that runs sentiment on all documents regardless of language; switching an English pipeline to Spanish while reusing the same analysis code; user requests for sentiment on Spanish text via the simple API.

Related errors


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

Appendix: source

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

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


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


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


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

}

View on GitHub (pinned to 1b7edd19c4)