{"record":{"id":"ae9327194c27f247","repo":"stanfordnlp/CoreNLP","slug":"doesn-t-do-k-sampled-yet","errorCode":null,"errorMessage":"Doesn't do k sampled yet","messagePattern":"Doesn't do k sampled yet","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java","lineNumber":858,"sourceCode":"   *  @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\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  @Override\n  public List<ScoredObject<Tree>> getKSampledParses(int k) {\n    throw new UnsupportedOperationException(\"Doesn't do k sampled yet\");\n  }\n\n}\n","sourceCodeStart":840,"sourceCodeEnd":862,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java#L840-L862","documentation":"Sentinel UnsupportedOperationException marking an unimplemented optional operation: ExhaustiveDependencyParser can score and rank dependency parses but has no mechanism to sample parses proportionally to their probability, so the getKSampledParses(int k) override simply throws. It fires whenever a caller requests stochastic parse samples from an exhaustive dependency parser instead of the supported k-best or good-parse queries.","triggerScenarios":"Calling getKSampledParses(k) on a ParserQuery backed by ExhaustiveDependencyParser.","commonSituations":"Monte-Carlo or sampling-based parse experiments that work over generic ParserQuery objects but are configured with the dependency parser, which never performs sampling.","solutions":["Use a sampling-capable parser implementation instead.","Catch UnsupportedOperationException and sample from k-best output of another parser, or use getBestParse().","Avoid sampling APIs when the configured parser is ExhaustiveDependencyParser."],"exampleFix":"// before\nList<ScoredObject<Tree>> samples = pq.getKSampledParses(20);\n// after\nList<ScoredObject<Tree>> samples;\ntry {\n  samples = pq.getKSampledParses(20);\n} catch (UnsupportedOperationException e) {\n  samples = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));\n}","handlingStrategy":"try-catch","validationCode":"// No shipping parser in lexparser supports sampling; avoid calling getKSampledParses entirely.","typeGuard":null,"tryCatchPattern":"try { samples = pq.getKSampledParses(k); } catch (UnsupportedOperationException e) { samples = sampleFromKBest(pq, k); }","preventionTips":["Implement sampling externally from k-best output.","Do not include getKSampledParses in generic parser abstraction paths.","Check javadoc capability notes before calling optional ParserQuery methods."],"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"}