stanfordnlp/CoreNLP · error · SsurgeonParseException
Unknown position in AddDep operation
Error message
Unknown position ${position} in AddDep operation What it means
The AddDep Ssurgeon operation constructor validates its 'position' argument, which must be an offset string starting with '-' (insert before the governor) or '+' (insert after). Any other non-null position string is rejected at construction time with this SsurgeonParseException, before the operation ever runs.
Solutions
- Use a signed offset string: pass null for default placement, or values like "-1" / "+1" (and generally -N/+N) for relative positions.
- If you do not need a relative position, pass null for position — the null check is skipped and AddDep falls back to computing an index (maxIndex + 1).
- Trim and normalize the position attribute when reading it from config before constructing AddDep.
- Wrap construction in try/catch for SsurgeonParseException and surface the bad rule/element to the rule author.
Example fix
// before
new AddDep("gov", rel, attrs, "after"); // throws
// after
new AddDep("gov", rel, attrs, "+1"); // or null for default placement Defensive patterns
Strategy: validation
Validate before calling
if (position != null && !(position.startsWith("-") || position.startsWith("+")))
throw new IllegalArgumentException("position must start with '-' or '+' (or be null): " + position); Try / catch
try { new AddDep(gov, rel, attrs, position); } catch (SsurgeonParseException e) { throw new IllegalArgumentException("Bad AddDep position: " + position, e); } Prevention
- Only pass signed offset strings or null for position
- Normalize/trim the position attribute read from rule XML before constructing
- Validate all AddDep constructor args (position, gov, relation) together in a rule loader
When it happens
Trigger: Constructing new AddDep(govNodeName, relation, attributes, position[, weight]) with a position string that does not start with '-' or '+', e.g. "after", "0", "before", or a stray space-prefixed value; also reached when Ssurgeon parses an AddDep element whose position attribute is misspelled or in the wrong format.
Common situations: Hand-editing Ssurgeon XML/rule files where the position attribute was written as a word instead of a signed offset; generated rules with a bad default; confusion between index-based insertion and the +/- relative-position convention.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- We need at least 2 extractors for ExtractorMerger to make…
- No governor given for an AddDep
- No relation given for an AddDep
- Cannot manually set the index attribute. If you need a…
- Cannot manually change the sentence index. If you need an…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a97081de89fe4ffe.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java:39
* @author Eric Yeh
*
*/
public class AddDep extends SsurgeonEdit {
public static final String LABEL = "addDep";
final Map<String, String> attributes;
final GrammaticalRelation relation;
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;
}
/**View on GitHub (pinned to 1b7edd19c4)