stanfordnlp/CoreNLP · error · UnsupportedOperationException
BiLexPCFGParser doesn't support best parses
Error message
BiLexPCFGParser doesn't support best parses
What it means
getBestParses is defined as returning all equally scoring best parses; BiLexPCFGParser does not implement this and throws UnsupportedOperationException, since it only produces a single sampled/chosen parse.
Solutions
- Use getBestParse() (singular) which BiLexPCFGParser supports
- Switch to the exhaustive PCFG parser if the set of tied best parses is required
- Check the query type before calling getBestParses
Example fix
// before List<ScoredObject<Tree>> bests = pq.getBestParses(); // after Tree best = pq.getBestParse();
Defensive patterns
Strategy: type-guard
Validate before calling
if (pq instanceof BiLexPCFGParser) {
// use getBestParse() instead
} Type guard
function supportsBestParses(pq) { return !(pq instanceof BiLexPCFGParser); } Try / catch
try {
return pq.getBestParses();
} catch (UnsupportedOperationException e) {
return Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));
} Prevention
- Call getBestParse() (singular) for BiLex queries
- Feature-detect query capabilities before use
- Avoid generic query-result extraction across parser implementations
When it happens
Trigger: Calling getBestParses() on a BiLexPCFGParser query object instead of on an ExhaustivePCFGParser query.
Common situations: Generic parser-query handling code that asks every query for all best parses; switching parser implementations without updating query result extraction.
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
- This language does not support GrammaticalStructures or…
- BiLexPCFGParser doesn't support k best parses
- BiLexPCFGParser doesn't support k sampled parses
- LogPrior.getSigmaSquaredM is undefined for any prior but…
- If you want to ask for the probability, you must train a…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d6e5472fcd5bd5e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/BiLexPCFGParser.java:176
*
* @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).
*/
public List<ScoredObject<Tree>> getKBestParses(int k) {
throw new UnsupportedOperationException("BiLexPCFGParser doesn't support k best parses");
}
/** 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
*/
public List<ScoredObject<Tree>> getBestParses() {
throw new UnsupportedOperationException("BiLexPCFGParser doesn't support best parses");
}
/** 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
*/
public List<ScoredObject<Tree>> getKSampledParses(int k) {
throw new UnsupportedOperationException("BiLexPCFGParser doesn't support k sampled parses");
}
protected Edge tempEdge;
protected void combine(Edge edge, Hook hook) {
if (VERBOSE) {
log.info("Combining: " + edge + " and " + hook);View on GitHub (pinned to 1b7edd19c4)