{"record":{"id":"84ceb2d6b65ce553","repo":"stanfordnlp/CoreNLP","slug":"bilexpcfgparser-doesn-t-support-k-sampled-parses","errorCode":null,"errorMessage":"BiLexPCFGParser doesn't support k sampled parses","messagePattern":"BiLexPCFGParser doesn't support k sampled parses","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/BiLexPCFGParser.java","lineNumber":187,"sourceCode":"  /** 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);\n    }\n    // make result edge\n    if (hook.isPreHook()) {\n      tempEdge.start = edge.start;\n      tempEdge.end = hook.end;\n    } else {\n      tempEdge.start = hook.start;\n      tempEdge.end = edge.end;\n    }\n    tempEdge.state = hook.state;\n    tempEdge.head = hook.head;","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/BiLexPCFGParser.java#L169-L205","documentation":"BiLexPCFGParser also does not implement stochastic sampling of k parses; getKSampledParses is a stub that throws UnsupportedOperationException, indicating sampling is unavailable in this constrained parser implementation.","triggerScenarios":"Calling getKSampledParses(k) on a BiLexPCFGParser query — e.g. code that samples multiple parses (like certain reranking or oracle experiments) while BiLex constrained parsing is selected.","commonSituations":"Oracle/parse-sampling experiments run with constrained parsing enabled; generic code paths that try sampling on any ParserQuery.","solutions":["Use the exhaustive PCFG parser query for k sampled parses","Set k to default single-parse behavior and use getBestParse() instead","Skip sampling logic when the query is a BiLexPCFGParser"],"exampleFix":"// before\nList<ScoredObject<Tree>> samples = pq.getKSampledParses(5);\n// after\nif (!(pq instanceof BiLexPCFGParser)) {\n  List<ScoredObject<Tree>> samples = pq.getKSampledParses(5);\n}","handlingStrategy":"type-guard","validationCode":"if (pq instanceof BiLexPCFGParser) {\n  throw new IllegalStateException(\"sampling unsupported under BiLex parsing\");\n}","typeGuard":"function supportsSampling(pq) { return !(pq instanceof BiLexPCFGParser); }","tryCatchPattern":"try {\n  return pq.getKSampledParses(k);\n} catch (UnsupportedOperationException e) {\n  return Collections.emptyList(); // sampling not available\n}","preventionTips":["Disable constrained/BiLex parsing for sampling experiments","Check query type before sampling APIs","Route sampling logic to ExhaustivePCFGParser queries only"],"tags":["java","stanford-parser","unsupported-operation","sampling"],"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"}