{"record":{"id":"58437238b3a09cd1","repo":"stanfordnlp/CoreNLP","slug":"got-a-tree-with-labels-which-do-not-support-lemma","errorCode":null,"errorMessage":"Got a tree with labels which do not support lemma","messagePattern":"Got a tree with labels which do not support lemma","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/TreeLemmatizer.java","lineNumber":37,"sourceCode":"\n    for (Tree leaf : t.getLeaves()) {\n      Label label = leaf.label();\n      if (label == null) {\n        continue;\n      }\n\n      String tag;\n      if (!(label instanceof HasTag) || ((HasTag) label).tag() == null) {\n        if (tagged == null) {\n          tagged = t.taggedYield();\n        }\n        tag = tagged.get(index).tag();\n      } else {\n        tag = ((HasTag) label).tag();\n      }\n\n      if (!(label instanceof HasLemma)) {\n        throw new IllegalArgumentException(\"Got a tree with labels which do not support lemma\");\n      }\n      ((HasLemma) label).setLemma(morphology.lemma(label.value(), tag, true));\n      ++index;\n    }\n    return t;\n  }\n\n}\n","sourceCodeStart":19,"sourceCodeEnd":46,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/TreeLemmatizer.java#L19-L46","documentation":"TreeLemmatizer.transformTree requires every labeled word in the tree to implement the HasLemma interface so it can set the lemma via setLemma(). If a label does not support lemmas (e.g. plain CoreLabel built without the feature, or a custom Label), it throws immediately.","triggerScenarios":"Running the lemmatizer (annotator or main/collins tree transforms) over trees whose labels are not HasLemma instances — e.g. trees built with LabeledScoredTreeFactory using StringLabel, or CoreLabels created without word/tag info.","commonSituations":"Mixing tree factories: building parse trees with a default factory that produces StringLabel instead of CoreLabel; feeding pre-parsed trees into Stanford dependency/lemma conversion pipelines.","solutions":["Build trees with CoreLabel-producing factories (e.g. LabeledScoredTreeFactory with CoreLabel factory or Tree.valueOf with a CoreLabel TreeReaderFactory).","Transform tree labels to CoreLabel before lemmatizing (e.g. Trees.toTree with a CoreLabel factory).","Ensure labels have value() and tag() populated so Morphology can compute the lemma."],"exampleFix":"// before\nTree t = Tree.valueOf(str); // StringLabel leaves\n// after\nTree t = new TreeReaderFactory() { ... }.newTreeReader(in).readTree(); // CoreLabel-backed","handlingStrategy":"type-guard","validationCode":"for (Label lab : tree.yield()) { if (!(lab instanceof HasLemma)) { /* convert labels to CoreLabel first */ } }","typeGuard":"boolean lemmatizable(Tree t) { return t.yield().stream().allMatch(l -> l instanceof HasLemma); }","tryCatchPattern":"try { lemmatizer.transformTree(tree); } catch (IllegalArgumentException e) { tree = relabelWithCoreLabels(tree); lemmatizer.transformTree(tree); }","preventionTips":["Build all trees with CoreLabel leaves.","Never use StringLabel/Word-based trees with the lemmatizer.","Check label types before running any label-property-dependent annotator."],"tags":["nlp","lemmatization","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}