stanfordnlp/CoreNLP · error · UnsupportedOperationException
ExhaustivePCFGParser doesn't sample.
Error message
ExhaustivePCFGParser doesn't sample.
What it means
Sentinel UnsupportedOperationException signalling a capability gap: ExhaustivePCFGParser only performs exact exhaustive parsing and can return k-best or good parses (getKGoodParses just delegates to getKBestParses), but it contains no sampling machinery to draw parses according to their relative probability. The error fires whenever getKSampledParses is called on this parser.
Solutions
- Sample manually from getKBestParses(k) output weighted by their scores.
- Use getKGoodParses(k) or getKBestParses(k) instead if an approximate list suffices.
- Implement external sampling: draw parses from the returned scored list using exp(-score) weights.
Example fix
// before List<ScoredObject<Tree>> samples = pq.getKSampledParses(10); // after List<ScoredObject<Tree>> best = pq.getKBestParses(100); List<ScoredObject<Tree>> samples = weightedSampleWithoutReplacement(best, 10, new Random());
Defensive patterns
Strategy: try-catch
Validate before calling
boolean supportsSampling = query.getClass().getSimpleName().contains("Factored") && !query.getClass().getSimpleName().contains("ExhaustivePCFG"); Try / catch
try { samples = pq.getKSampledParses(k); } catch (UnsupportedOperationException e) { samples = weightedSample(pq.getKBestParses(100), k); } Prevention
- Assume ExhaustivePCFGParser provides only exact/approximate k-best, not sampling.
- Derive samples from scored k-best lists with probability exp(score).
- Keep sampling logic outside the parser abstraction layer.
When it happens
Trigger: Calling getKSampledParses(k) on a ParserQuery produced by ExhaustivePCFGParser after parsing.
Common situations: Code that uniformly requests sampled parses across parser implementations; PCFG parser has no sampling machinery despite having k-best support.
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
- Doesn't do k best yet
- Doesn't do best parses yet
- Doesn't do k good yet
- Doesn't do k sampled yet
- FastFactoredParser: cannot provide k good parses.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6559bf75b19e8479.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java:1807
* @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) {
return getKBestParses(k);
}
/** 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("ExhaustivePCFGParser doesn't sample.");
}
//
// BEGIN K-BEST STUFF
// taken straight out of "Better k-best Parsing" by Liang Huang and David
// Chiang
//
/** Get the exact k best parses for the sentence.
*
* @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) {View on GitHub (pinned to 1b7edd19c4)