{"record":{"id":"0bf0e4b6108d6716","repo":"stanfordnlp/CoreNLP","slug":"setphrasehead-expected-a-reln-to-represent-the-de","errorCode":null,"errorMessage":"SetPhraseHead expected a -reln to represent the dependency to use for the new phrase","messagePattern":"SetPhraseHead expected a -reln to represent the dependency to use for the new phrase","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetPhraseHead.java","lineNumber":39,"sourceCode":" */\npublic class SetPhraseHead extends SsurgeonEdit {\n  public static final String LABEL = \"setPhraseHead\";\n\n  final List<String> phrase;\n  final int headIndex;\n  final GrammaticalRelation relation;\n  final double weight;\n\n  public SetPhraseHead(List<String> nodes, Integer headIndex, GrammaticalRelation relation, double weight) {\n    if (headIndex == null) {\n      throw new SsurgeonParseException(\"SetPhraseHead expected a -headIndex, 0-indexed for the node to use as the new head\");\n    }\n    if (headIndex < 0 || headIndex >= nodes.size()) {\n      throw new SsurgeonParseException(\"-headIndex of \" + headIndex + \" is out of bounds for a phrase with \" + nodes.size() + \" words\");\n    }\n\n    if (relation == null) {\n      throw new SsurgeonParseException(\"SetPhraseHead expected a -reln to represent the dependency to use for the new phrase\");\n    }\n\n    this.phrase = new ArrayList<>(nodes);\n    this.headIndex = headIndex;\n    this.relation = relation;\n    this.weight = weight;\n  }\n\n  @Override\n  public String toEditString() {\n    StringWriter buf = new StringWriter();\n    buf.write(LABEL);\n    buf.write(\"\\t\");\n    for (String node : phrase) {\n      buf.write(\"-node \" + node + \"\\t\");\n    }\n    buf.write(\"-headIndex \" + headIndex + \"\\t\");\n    buf.write(\"-reln \" + relation.toString());","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetPhraseHead.java#L21-L57","documentation":"SetPhraseHead needs a GrammaticalRelation for the dependency that will point at the new phrase head; if the relation argument is null the operation cannot construct the new edge and throws SsurgeonParseException.","triggerScenarios":"new SetPhraseHead(nodes, headIndex, null, weight), or a set-phrase-head resource line with a missing or unresolvable -reln argument.","commonSituations":"Omitting -reln in a hand-written rule; a typo in the relation short name so parsing yields null; copying a rule template that left the relation blank.","solutions":["Add -reln with a valid universal dependency relation name (e.g. -reln dep) to the set-phrase-head line","Pass a GrammaticalRelation instance such as UniversalGrammaticalRelations.DEPENDENT programmatically","Verify the relation name against edu.stanford.nlp.trees.UniversalGrammaticalRelations names"],"exampleFix":"// before\nnew SetPhraseHead(nodes, 0, null, 1.0);\n// after\nnew SetPhraseHead(nodes, 0, UniversalGrammaticalRelations.DEPENDENT, 1.0);","handlingStrategy":"validation","validationCode":"if (relation == null) {\n  throw new IllegalArgumentException(\"set-phrase-head requires a -reln GrammaticalRelation\");\n}","typeGuard":"boolean hasRelation(GrammaticalRelation r) { return r != null; }","tryCatchPattern":"try {\n  op = new SetPhraseHead(nodes, headIndex, relation, weight);\n} catch (SsurgeonParseException e) {\n  log.error(\"set-phrase-head missing -reln: {}\", e.getMessage());\n  op = new SetPhraseHead(nodes, headIndex, UniversalGrammaticalRelations.DEPENDENT, weight);\n}","preventionTips":["Include -reln on every set-phrase-head line in Ssurgeon resource files","Use UniversalGrammaticalRelations constants when building operations in code","Validate all relation names with a unit test that constructs each rule operation"],"tags":["java","ssurgeon","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}