stanfordnlp/CoreNLP · error · RuntimeException
Error: Haven't dealt with relation " + relation + " yet.
Error message
Error: Haven't dealt with relation " + relation + " yet.
What it means
TreeLocation.evaluate handles only the $+ and $- (right/left sister) relations in its switch; any other relation string reaching this code path hits the default branch and throws "Haven't dealt with relation X yet". It signals an unsupported or malformed relation in a tsurgeon location expression.
Solutions
- Correct the relation to "$+" or "$-" in the tsurgeon expression
- Parse the operation through Tsurgeon.parseOperation so malformed relations are rejected up front with a clearer TsurgeonParseException
- If a new relation is needed, extend the switch in TreeLocation.evaluate
Example fix
// before
parseOperation("insert (NP foo) $~NP");
// after
parseOperation("insert (NP foo) $+NP"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> supported = Set.of("$+", "$");
// validate relations in the tsurgeon script before evaluating
boolean ok = scriptRelations.stream().allMatch(supported::contains); Type guard
null
Try / catch
try { evaluate(loc, tree); } catch (RuntimeException e) { if (e.getMessage().startsWith("Error: Haven't dealt with relation")) { throw new IllegalArgumentException("Unsupported tsurgeon relation", e); } throw e; } Prevention
- Use only documented tsurgeon relations ($+, $-)
- Parse scripts through Tsurgeon.parseOperation instead of building internals manually
- Keep parser and TreeLocation versions in sync when upgrading Stanford CoreNLP
When it happens
Trigger: Calling TreeLocation.evaluate with a relation string other than "$+" or "$-", e.g. a typo like "$++", "$", or a relation inserted programmatically rather than parsed by TsurgeonParser.
Common situations: Hand-constructing Tsurgeon internals instead of using parseOperation; typos in relation names in tsurgeon scripts; library version where a new relation is used but TreeLocation hasn't been updated.
Related errors
- Error: looking for a non-existent parent in tree " + tree +…
- Tsurgeon.processPatternsOnTree failed to match label for…
- Null node fetched by Tsurgeon operation for node:
- Error initializing coref system
- Error making document
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2a179328bb64ae45.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/tregex/tsurgeon/TreeLocation.java:73
newIndex = Integer.parseInt(m.group(1))-1;
parent = relativeNode;
if(relation.charAt(1)=='-') // backwards.
newIndex = parent.children().length - newIndex;
} else {
parent = relativeNode.parent(tree);
if (parent == null) {
throw new RuntimeException("Error: looking for a non-existent parent in tree " + tree + " for \"" + toString() + '"');
}
int index = parent.objectIndexOf(relativeNode);
switch(relation) {
case "$+" :
newIndex = index;
break;
case "$-" :
newIndex = index+1;
break;
default :
throw new RuntimeException("Error: Haven't dealt with relation " + relation + " yet.");
}
}
return new Pair<>(parent, newIndex);
}
}
@Override
public String toString() {
return relation + ' ' + child;
}
}
View on GitHub (pinned to 1b7edd19c4)