stanfordnlp/CoreNLP · error · UnsupportedOperationException
Doesn't do k best yet
Error message
Doesn't do k best yet
What it means
ExhaustiveDependencyParser implements the ParserQuery interface but does not support extracting the exact k best parses. getKBestParses(int) is a stub that unconditionally throws UnsupportedOperationException. The parser only computes a single Viterbi-style best parse.
Solutions
- Use ExhaustivePCFGParser (or another k-best capable parser) instead of ExhaustiveDependencyParser when k-best output is needed.
- Wrap the call in a try-catch for UnsupportedOperationException and degrade to getBestParse().
- Check interface capability before calling; call getBestParse() for the single best dependency parse.
Example fix
// before
List<ScoredObject<Tree>> parses = pq.getKBestParses(10);
// after
List<ScoredObject<Tree>> parses;
try {
parses = pq.getKBestParses(10);
} catch (UnsupportedOperationException e) {
parses = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));
} Defensive patterns
Strategy: try-catch
Validate before calling
// k-best capability check
if (query.getClass().getSimpleName().contains("ExhaustiveDependencyParser")) {
throw new IllegalArgumentException("k-best not supported by this parser");
} Try / catch
try { parses = pq.getKBestParses(k); } catch (UnsupportedOperationException e) { parses = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore())); } Prevention
- Know which ParserQuery implementation your parser factory produces before using k-best APIs.
- Document at call sites that k-best requires a k-best-capable parser.
- Centralize parse-list retrieval in a helper that degrades gracefully.
When it happens
Trigger: Calling getKBestParses(k) on a ParserQuery produced by ExhaustiveDependencyParser, e.g. via parserQuery.getKBestParses(10) after a successful parse.
Common situations: Code written against a shared ParserQuery/BiLexiconizedParser interface that assumes k-best support, but configured with a dependency grammar / ExhaustiveDependencyParser factory instead of ExhaustivePCFGParser.
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 best parses yet
- Doesn't do k good yet
- Doesn't do k sampled yet
- ExhaustivePCFGParser doesn't sample.
- FastFactoredParser: cannot provide k good parses.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/7805da370dcd01ad.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java:820
iPossibleByR = new boolean[length + 1][length + 1][tagNum];
oPossibleByL = new boolean[length + 1][length + 1][tagNum];
oPossibleByR = new boolean[length + 1][length + 1][tagNum];
headScore = new float[dg.numDistBins()][length][tagNum][length][tagNum];
headStop = new float[length + 1][tagNum][length + 1];
rawDistance = new int[length + 1][length + 1];
binDistance = new int[length + 1][length + 1];
}
/** 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) {
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.View on GitHub (pinned to 1b7edd19c4)