stanfordnlp/CoreNLP · error · UnsupportedOperationException

Doesn't do k sampled yet

Error message

Doesn't do k sampled yet

What it means

Sentinel UnsupportedOperationException marking an unimplemented optional operation: ExhaustiveDependencyParser can score and rank dependency parses but has no mechanism to sample parses proportionally to their probability, so the getKSampledParses(int k) override simply throws. It fires whenever a caller requests stochastic parse samples from an exhaustive dependency parser instead of the supported k-best or good-parse queries.

Solutions

  1. Use a sampling-capable parser implementation instead.
  2. Catch UnsupportedOperationException and sample from k-best output of another parser, or use getBestParse().
  3. Avoid sampling APIs when the configured parser is ExhaustiveDependencyParser.

Example fix

// before
List<ScoredObject<Tree>> samples = pq.getKSampledParses(20);
// after
List<ScoredObject<Tree>> samples;
try {
  samples = pq.getKSampledParses(20);
} catch (UnsupportedOperationException e) {
  samples = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// No shipping parser in lexparser supports sampling; avoid calling getKSampledParses entirely.

Try / catch

try { samples = pq.getKSampledParses(k); } catch (UnsupportedOperationException e) { samples = sampleFromKBest(pq, k); }

Prevention

When it happens

Trigger: Calling getKSampledParses(k) on a ParserQuery backed by ExhaustiveDependencyParser.

Common situations: Monte-Carlo or sampling-based parse experiments that work over generic ParserQuery objects but are configured with the dependency parser, which never performs sampling.

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

Appendix: source

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

   *  @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
   *  parses are sampled based on their relative probability.
   *
   *  @param k The number of sampled parses to return
   *  @return A list of k parse samples for the sentence, with
   *         each accompanied by its score
   */
  @Override
  public List<ScoredObject<Tree>> getKSampledParses(int k) {
    throw new UnsupportedOperationException("Doesn't do k sampled yet");
  }

}

View on GitHub (pinned to 1b7edd19c4)