stanfordnlp/CoreNLP · error · UnsupportedOperationException

This version of the parser does not support non-tree…

Error message

This version of the parser does not support non-tree training data

What it means

ChineseLexiconAndWordSegmenter.trainUnannotated is a required interface method (from the Lexicon API) that should train the segmenter on unannotated (non-treebank) sentences. This implementation is an explicit stub that punts on the feature and throws UnsupportedOperationException whenever the parser framework feeds raw, non-tree training data to the Chinese lexicon/segmenter.

Solutions

  1. Restrict training data to annotated treebank trees so trainUnannotated is never invoked
  2. Switch to a lexicon implementation that supports unannotated training, or extend ChineseLexiconAndWordSegmenter to implement trainUnannotated by delegating to wordSegmenter training
  3. Use an older/newer Stanford NLP release or the BaseLexicon path that handles raw data differently

Example fix

// before
lexicon.trainUnannotated(rawSentences, 1.0); // throws UnsupportedOperationException
// after
lexicon.train(treebankSentences); // only annotated trees are supported
Defensive patterns

Strategy: validation

Validate before calling

if (data instanceof List && !isAnnotatedTreebank(data)) { throw new IllegalArgumentException("trainUnannotated unsupported; use annotated trees"); }

Type guard

boolean supportsUnannotated(Object lex) { return !(lex instanceof ChineseLexiconAndWordSegmenter); }

Try / catch

try { lexicon.trainUnannotated(sentences, w); } catch (UnsupportedOperationException e) { log.warn("Non-tree training unsupported, skipping"); }

Prevention

When it happens

Trigger: Calling trainUnannotated(List<TaggedWord>, double) directly, or running a training pipeline that uses unannotated/raw training data (e.g. unsupervised or semi-supervised training options) with the Chinese lexicon and word segmenter.

Common situations: Developers attempting semi-supervised training on raw Chinese text (e.g. -train2 or unannotated-data options) discover this lexicon variant never implemented the feature; it is a known TODO in the source.

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/ffd4912d52c3ffb7. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseLexiconAndWordSegmenter.java:128

  public void train(Tree tree, double weight) {
    train(tree.taggedYield(), weight);
  }

  @Override
  public void train(List<TaggedWord> sentence) {
    train(sentence, 1.0);
  }

  @Override
  public void train(List<TaggedWord> sentence, double weight) {
    chineseLexicon.train(sentence, weight);
    wordSegmenter.train(sentence);
  }

  @Override
  public void trainUnannotated(List<TaggedWord> sentence, double weight) {
    // TODO: for now we just punt on these
    throw new UnsupportedOperationException("This version of the parser does not support non-tree training data");
  }

  @Override
  public void incrementTreesRead(double weight) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void train(TaggedWord tw, int loc, double weight) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void finishTraining() {
    chineseLexicon.finishTraining();
    wordSegmenter.finishTraining();
  }

View on GitHub (pinned to 1b7edd19c4)