stanfordnlp/CoreNLP · error · UnsupportedOperationException

Doesn't do best parses yet

Error message

Doesn't do best parses yet

What it means

ExhaustiveDependencyParser does not implement getBestParses(), which should return all parses tied for the best score. The method is an unsupported stub that always throws UnsupportedOperationException.

Solutions

  1. Use ExhaustivePCFGParser, which implements getBestParses(), instead.
  2. Catch UnsupportedOperationException and fall back to the single getBestParse() result.
  3. Rework the analysis to not require the full set of tied best parses.

Example fix

// before
List<ScoredObject<Tree>> best = pq.getBestParses();
// after
List<ScoredObject<Tree>> best;
try {
  best = pq.getBestParses();
} catch (UnsupportedOperationException e) {
  Tree t = pq.getBestParse();
  best = t == null ? Collections.emptyList() : Collections.singletonList(new ScoredObject<>(t, pq.getBestScore()));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// only ExhaustivePCFGParser supports getBestParses
boolean supportsBestParses = !(query instanceof ParserQuery) || query.getClass().getSimpleName().contains("PCFG");

Try / catch

try { best = pq.getBestParses(); } catch (UnsupportedOperationException e) { best = fallbackBestList(pq); }

Prevention

When it happens

Trigger: Calling getBestParses() on a ParserQuery backed by ExhaustiveDependencyParser after parsing a sentence.

Common situations: Code that enumerates all equally-scored best parses (e.g. for parser evaluation or ambiguity studies) run against a dependency parser that only tracks one best hypothesis.

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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java:831

   *  @param k The number of best parses to return
   *  @return The exact k best parses for the sentence, with
   *         each accompanied by its score (typically a
   *         negative log probability).
   */
  @Override
  public List<ScoredObject<Tree>> getKBestParses(int k) {
    throw new UnsupportedOperationException("Doesn't do k best yet");
  }

  /** Get a complete set of the maximally scoring parses for a sentence,
   *  rather than one chosen at random.  This set may be of size 1 or larger.
   *
   *  @return All the equal best parses for a sentence, with each
   *         accompanied by its score
   */
  @Override
  public List<ScoredObject<Tree>> getBestParses() {
    throw new UnsupportedOperationException("Doesn't do best parses yet");
  }

  /** Get k good parses for the sentence.  It is expected that the
   *  parses returned approximate the k best parses, but without any
   *  guarantee that the exact list of k best parses has been produced.
   *  If a class really provides k best parses functionality, it is
   *  reasonable to also return this output as the k good parses.
   *
   *  @param k The number of good parses to return
   *  @return A list of k good parses for the sentence, with
   *         each accompanied by its score
   */
  @Override
  public List<ScoredObject<Tree>> getKGoodParses(int k) {
    throw new UnsupportedOperationException("Doesn't do k good yet");
  }

  /** Get k parse samples for the sentence.  It is expected that the

View on GitHub (pinned to 1b7edd19c4)