{"record":{"id":"ad2628642df36731","repo":"stanfordnlp/CoreNLP","slug":"doesn-t-do-best-parses-yet","errorCode":null,"errorMessage":"Doesn't do best parses yet","messagePattern":"Doesn't do best parses yet","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java","lineNumber":831,"sourceCode":"   *  @param k The number of best parses to return\n   *  @return The exact k best parses for the sentence, with\n   *         each accompanied by its score (typically a\n   *         negative log probability).\n   */\n  @Override\n  public List<ScoredObject<Tree>> getKBestParses(int k) {\n    throw new UnsupportedOperationException(\"Doesn't do k best yet\");\n  }\n\n  /** Get a complete set of the maximally scoring parses for a sentence,\n   *  rather than one chosen at random.  This set may be of size 1 or larger.\n   *\n   *  @return All the equal best parses for a sentence, with each\n   *         accompanied by its score\n   */\n  @Override\n  public List<ScoredObject<Tree>> getBestParses() {\n    throw new UnsupportedOperationException(\"Doesn't do best parses yet\");\n  }\n\n  /** Get k good parses for the sentence.  It is expected that the\n   *  parses returned approximate the k best parses, but without any\n   *  guarantee that the exact list of k best parses has been produced.\n   *  If a class really provides k best parses functionality, it is\n   *  reasonable to also return this output as the k good parses.\n   *\n   *  @param k The number of good parses to return\n   *  @return A list of k good parses for the sentence, with\n   *         each accompanied by its score\n   */\n  @Override\n  public List<ScoredObject<Tree>> getKGoodParses(int k) {\n    throw new UnsupportedOperationException(\"Doesn't do k good yet\");\n  }\n\n  /** Get k parse samples for the sentence.  It is expected that the","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java#L813-L849","documentation":"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.","triggerScenarios":"Calling getBestParses() on a ParserQuery backed by ExhaustiveDependencyParser after parsing a sentence.","commonSituations":"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.","solutions":["Use ExhaustivePCFGParser, which implements getBestParses(), instead.","Catch UnsupportedOperationException and fall back to the single getBestParse() result.","Rework the analysis to not require the full set of tied best parses."],"exampleFix":"// before\nList<ScoredObject<Tree>> best = pq.getBestParses();\n// after\nList<ScoredObject<Tree>> best;\ntry {\n  best = pq.getBestParses();\n} catch (UnsupportedOperationException e) {\n  Tree t = pq.getBestParse();\n  best = t == null ? Collections.emptyList() : Collections.singletonList(new ScoredObject<>(t, pq.getBestScore()));\n}","handlingStrategy":"try-catch","validationCode":"// only ExhaustivePCFGParser supports getBestParses\nboolean supportsBestParses = !(query instanceof ParserQuery) || query.getClass().getSimpleName().contains(\"PCFG\");","typeGuard":null,"tryCatchPattern":"try { best = pq.getBestParses(); } catch (UnsupportedOperationException e) { best = fallbackBestList(pq); }","preventionTips":["Use ExhaustivePCFGParser when tied-best enumeration is required.","Wrap unsupported ParserQuery methods behind capability-detecting helpers.","Log the parser class name in errors to speed diagnosis."],"tags":["java","nlp","parsing","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}