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

ChineseMaxentLexicon.trainUnannotated is an explicit stub that refuses non-tree training data, same as the ChineseLexiconAndWordSegmenter variant. The parser interface allows feeding raw unannotated sentences with a weight, but this lexicon never implemented it and throws UnsupportedOperationException as a TODO.

Solutions

  1. Use only annotated treebank data (call train(...) instead)
  2. Subclass ChineseMaxentLexicon and implement trainUnannotated to accumulate raw-sentence statistics
  3. Choose a different lexicon/unknown word model that supports unannotated training

Example fix

// before
maxentLexicon.trainUnannotated(rawSentences, 1.0); // throws
// after
maxentLexicon.train(annotatedTrees);
Defensive patterns

Strategy: validation

Validate before calling

if (!annotatedOnly && lexicon instanceof ChineseMaxentLexicon) throw new IllegalArgumentException("ChineseMaxentLexicon does not support unannotated training");

Type guard

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

Try / catch

try { lexicon.trainUnannotated(raw, w); } catch (UnsupportedOperationException e) { fallbackToAnnotatedTraining(); }

Prevention

When it happens

Trigger: Calling trainUnannotated(List<TaggedWord>, double) on a ChineseMaxentLexicon, directly or via a training framework configured to use unannotated/raw data.

Common situations: Semi-supervised Chinese parsing experiments that mix treebank data with raw corpora hit this immediately; the feature is simply unimplemented for this lexicon class.

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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseMaxentLexicon.java:268

  }

  /**
   * Add the given sentence to the statistics counted.  Can
   * be called multiple times with different sentences.
   */
  @Override
  public void train(List<TaggedWord> sentence, double weight) {
    featExtractor.train(sentence, weight);
    for (TaggedWord word : sentence) {
      datumCounter.incrementCount(word, weight);
      tagsForWord.add(word.word(), word.tag());
    }
  }

  @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() {
    IntCounter<String> tagCounter = new IntCounter<>();

    WeightedDataset data = new WeightedDataset(datumCounter.size());

View on GitHub (pinned to 1b7edd19c4)