{"record":{"id":"96c93d2b7c93dc2d","repo":"stanfordnlp/CoreNLP","slug":"no-label-for-text","errorCode":null,"errorMessage":"No label for '\" + text + \"'","messagePattern":"No label for '\" \\+ text \\+ \"'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":74,"sourceCode":"    FAIL, DEFAULT, KEEP_ORIGINAL\n  }\n\n  private ParseAndSetLabels() {} // static methods\n\n  public static void setLabels(Tree tree, Map<String, String> labelMap,\n                               MissingLabels missing, String defaultLabel,\n                               Set<String> unknowns) {\n    if (tree.isLeaf()) {\n      return;\n    }\n    String text = SentenceUtils.listToString(tree.yield());\n    String label = labelMap.get(text);\n    if (label != null) {\n      tree.label().setValue(label);\n    } else {\n      switch (missing) {\n      case FAIL:\n        throw new RuntimeException(\"No label for '\" + text + \"'\");\n      case DEFAULT:\n        tree.label().setValue(defaultLabel);\n        unknowns.add(text);\n        break;\n      case KEEP_ORIGINAL:\n        // do nothing\n        break;\n      default:\n        throw new IllegalArgumentException(\"Unknown MissingLabels mode \" + missing);\n      }\n    }\n    for (Tree child : tree.children()) {\n      setLabels(child, labelMap, missing, defaultLabel, unknowns);\n    }\n  }\n\n  public static Set<String> setLabels(List<Tree> trees, Map<String, String> labelMap,\n                                      MissingLabels missing, String defaultLabel) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L56-L92","documentation":"ParseAndSetLabels attaches predicted labels to tree nodes using a text->label map; when a tree node's text has no entry in the labelMap and the MissingLabels policy is FAIL, it throws a RuntimeException with the unmatched text. This is a hard-fail mode so unmapped nodes are never silently mislabeled.","triggerScenarios":"Running ParseAndSetLabels with -missingLabels FAIL (the strict default) while the labels file lacks an entry for a token that appears in the trees/sentences being processed — e.g. the quoted string in \"No label for 'X'\" names the missing text.","commonSituations":"Labels file built from a different corpus than the input trees; tokenization differences producing unseen surface forms; case/whitespace mismatches between keys and tree text; OOV words at test time.","solutions":["Add the missing text 'X' to the labels file so the map covers all inputs","Run with a tolerant policy (-missingLabelsOptions defaultLabel=NONE or keepOriginal) if strict failure is not needed","Normalize tokenization/casing so tree text matches label keys","Diff the set of tree texts against the label map keys before running to find gaps"],"exampleFix":"// before\n// java ParseAndSetLabels -labels labels.txt -missingLabels FAIL ... \n// after\n// java ParseAndSetLabels -labels labels.txt -missingLabels defaultLabel=UNKNOWN ...","handlingStrategy":"validation","validationCode":"java.util.Set<String> texts = collectTreeTexts(trees);\njava.util.Set<String> keys = labelMap.keySet();\ntexts.removeAll(keys);\nif (!texts.isEmpty()) throw new IllegalStateException(\"texts missing from label map: \" + texts);","typeGuard":null,"tryCatchPattern":"try {\n  tool.run();\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"No label for\")) {\n    System.err.println(\"Extend your labels file for: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Precompute coverage of all tree texts against the label map","Use a tolerant missing-labels policy for production runs","Keep tokenization identical between label extraction and tree processing"],"tags":["java","nlp","labels"],"backgroundTag":"resource-not-found","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"}