stanfordnlp/CoreNLP · error · SsurgeonParseException

SetPhraseHead expected a -reln to represent the dependency…

Error message

SetPhraseHead expected a -reln to represent the dependency to use for the new phrase

What it means

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.

Solutions

  1. Add -reln with a valid universal dependency relation name (e.g. -reln dep) to the set-phrase-head line
  2. Pass a GrammaticalRelation instance such as UniversalGrammaticalRelations.DEPENDENT programmatically
  3. Verify the relation name against edu.stanford.nlp.trees.UniversalGrammaticalRelations names

Example fix

// before
new SetPhraseHead(nodes, 0, null, 1.0);
// after
new SetPhraseHead(nodes, 0, UniversalGrammaticalRelations.DEPENDENT, 1.0);
Defensive patterns

Strategy: validation

Validate before calling

if (relation == null) {
  throw new IllegalArgumentException("set-phrase-head requires a -reln GrammaticalRelation");
}

Type guard

boolean hasRelation(GrammaticalRelation r) { return r != null; }

Try / catch

try {
  op = new SetPhraseHead(nodes, headIndex, relation, weight);
} catch (SsurgeonParseException e) {
  log.error("set-phrase-head missing -reln: {}", e.getMessage());
  op = new SetPhraseHead(nodes, headIndex, UniversalGrammaticalRelations.DEPENDENT, weight);
}

Prevention

When it happens

Trigger: new SetPhraseHead(nodes, headIndex, null, weight), or a set-phrase-head resource line with a missing or unresolvable -reln argument.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/0bf0e4b6108d6716. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetPhraseHead.java:39

 */
public class SetPhraseHead extends SsurgeonEdit {
  public static final String LABEL = "setPhraseHead";

  final List<String> phrase;
  final int headIndex;
  final GrammaticalRelation relation;
  final double weight;

  public SetPhraseHead(List<String> nodes, Integer headIndex, GrammaticalRelation relation, double weight) {
    if (headIndex == null) {
      throw new SsurgeonParseException("SetPhraseHead expected a -headIndex, 0-indexed for the node to use as the new head");
    }
    if (headIndex < 0 || headIndex >= nodes.size()) {
      throw new SsurgeonParseException("-headIndex of " + headIndex + " is out of bounds for a phrase with " + nodes.size() + " words");
    }

    if (relation == null) {
      throw new SsurgeonParseException("SetPhraseHead expected a -reln to represent the dependency to use for the new phrase");
    }

    this.phrase = new ArrayList<>(nodes);
    this.headIndex = headIndex;
    this.relation = relation;
    this.weight = weight;
  }

  @Override
  public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);
    buf.write("\t");
    for (String node : phrase) {
      buf.write("-node " + node + "\t");
    }
    buf.write("-headIndex " + headIndex + "\t");
    buf.write("-reln " + relation.toString());

View on GitHub (pinned to 1b7edd19c4)