stanfordnlp/CoreNLP · error · SsurgeonParseException

No relation given for an AddDep

Error message

No relation given for an AddDep

What it means

AddDep requires a GrammaticalRelation for the new dependency edge; a null relation cannot produce a valid SemanticGraphEdge, so the constructor throws this SsurgeonParseException after the governor check.

Solutions

  1. Pass a valid GrammaticalRelation instance (e.g. GrammaticalRelation.valueOf / the appropriate UniversalEnglishGrammaticalRelations constant).
  2. If starting from a string, resolve it explicitly and fail early with a clear message when valueOf returns/throws for an unknown relation.
  3. Fix the Ssurgeon rule so its relation attribute is present and spelled exactly as a valid UD relation.
  4. When auditing AddDep call sites, validate govNodeName, relation, and position together — the constructor checks all three.

Example fix

// before
new AddDep("gov", null, attrs, "+1"); // throws
// after
GrammaticalRelation rel = UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT;
new AddDep("gov", rel, attrs, "+1");
Defensive patterns

Strategy: validation

Validate before calling

if (relation == null) throw new IllegalArgumentException("AddDep requires a GrammaticalRelation");

Try / catch

try { new AddDep(gov, rel, attrs, pos); } catch (SsurgeonParseException e) { throw new IllegalArgumentException("AddDep missing relation", e); }

Prevention

When it happens

Trigger: Calling new AddDep(govNodeName, null, attributes, position[, weight]); also occurs when Ssurgeon rule parsing builds an AddDep element with a missing or unrecognized relation attribute that resolves to null.

Common situations: Rule files missing the relation attribute; a relation string that failed to map to a GrammaticalRelation (e.g. not resolvable via UniversalSemanticGraphConverter/EnglishGrammaticalRelations); programmatic rule generation leaving relation unset.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java:46

  final String govNodeName;
  final String position;
  final double weight;

  public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, String> attributes, String position) {
    this(govNodeName, relation, attributes, position, 0.0);
  }

  public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, String> attributes, String position, double weight) {
    if (position != null) {
      if (!position.startsWith("-") && !position.startsWith("+")) {
        throw new SsurgeonParseException("Unknown position " + position + " in AddDep operation");
      }
    }
    if (govNodeName == null) {
      throw new SsurgeonParseException("No governor given for an AddDep");
    }
    if (relation == null) {
      throw new SsurgeonParseException("No relation given for an AddDep");
    }
    checkIllegalAttributes(attributes);

    this.attributes = new TreeMap<>(attributes);
    this.relation = relation;
    this.govNodeName = govNodeName;
    this.position = position;
    this.weight = weight;
  }

  /**
   * Emits a parseable instruction string.
   */
  @Override
  public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL);  buf.write("\t");
    buf.write(Ssurgeon.GOV_NODENAME_ARG);buf.write(" ");

View on GitHub (pinned to 1b7edd19c4)