{"record":{"id":"d6e5472fcd5bd5e7","repo":"stanfordnlp/CoreNLP","slug":"bilexpcfgparser-doesn-t-support-best-parses","errorCode":null,"errorMessage":"BiLexPCFGParser doesn't support best parses","messagePattern":"BiLexPCFGParser doesn't support best parses","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/BiLexPCFGParser.java","lineNumber":176,"sourceCode":"   *\n   *  @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  public List<ScoredObject<Tree>> getKBestParses(int k) {\n    throw new UnsupportedOperationException(\"BiLexPCFGParser doesn't support k best parses\");\n  }\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  public List<ScoredObject<Tree>> getBestParses() {\n    throw new UnsupportedOperationException(\"BiLexPCFGParser doesn't support best parses\");\n  }\n\n  /** Get k parse samples for the sentence.  It is expected that the\n   *  parses are sampled based on their relative probability.\n   *\n   *  @param k The number of sampled parses to return\n   *  @return A list of k parse samples for the sentence, with\n   *         each accompanied by its score\n   */\n  public List<ScoredObject<Tree>> getKSampledParses(int k) {\n    throw new UnsupportedOperationException(\"BiLexPCFGParser doesn't support k sampled parses\");\n  }\n\n  protected Edge tempEdge;\n\n  protected void combine(Edge edge, Hook hook) {\n    if (VERBOSE) {\n      log.info(\"Combining: \" + edge + \" and \" + hook);","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/BiLexPCFGParser.java#L158-L194","documentation":"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.","triggerScenarios":"Calling getBestParses() on a BiLexPCFGParser query object instead of on an ExhaustivePCFGParser query.","commonSituations":"Generic parser-query handling code that asks every query for all best parses; switching parser implementations without updating query result extraction.","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"],"exampleFix":"// before\nList<ScoredObject<Tree>> bests = pq.getBestParses();\n// after\nTree best = pq.getBestParse();","handlingStrategy":"type-guard","validationCode":"if (pq instanceof BiLexPCFGParser) {\n  // use getBestParse() instead\n}","typeGuard":"function supportsBestParses(pq) { return !(pq instanceof BiLexPCFGParser); }","tryCatchPattern":"try {\n  return pq.getBestParses();\n} catch (UnsupportedOperationException e) {\n  return Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));\n}","preventionTips":["Call getBestParse() (singular) for BiLex queries","Feature-detect query capabilities before use","Avoid generic query-result extraction across parser implementations"],"tags":["java","stanford-parser","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"}