stanfordnlp/CoreNLP · error · SemgrexParseException
GraphRelation had both = and ~ set, but the names were…
Error message
GraphRelation had both = and ~ set, but the names were different!
What it means
The GraphRelation constructor throws SemgrexParseException when both a node-name binding (=name) and an edge-name binding (~name) are present but differ. A GraphRelation can only carry one consistent name; conflicting names would make the pattern ambiguous.
Solutions
- Use the same name for both = and ~ bindings, or drop one of them
- Edit the Semgrex pattern string so the node name (=x) and edge name (~x) match
- If names must differ, keep only the one you intend to bind
Example fix
// before
String pattern = "{word:dog} >=subj=nsubj~edge";
// after
String pattern = "{word:dog} >=subj=nsubj~subj"; Defensive patterns
Strategy: try-catch
Validate before calling
if (name != null && edgeName != null && !name.equals(edgeName)) throw new IllegalArgumentException("= and ~ names must match: " + name + " vs " + edgeName); Try / catch
try { GraphRelation r = GraphRelation.createRelation(reln, type, name, edgeName); } catch (SemgrexParseException e) { log.error("Inconsistent pattern names: " + e.getMessage()); } Prevention
- Use identical names for = (node) and ~ (edge) bindings in Semgrex patterns
- Validate pattern strings with the Semgrex parser before deploying them in configs
- Keep name tokens generated from one variable so they cannot diverge
When it happens
Trigger: Parsing a Semgrex relation like ">=foo~bar" where the = name and the ~ edgeName are both set to different strings, via GraphRelation.createRelation or the Semgrex parser.
Common situations: Typo in a hand-written Semgrex pattern assigning different names to the node and the edge; generated patterns concatenating name fragments incorrectly.
Related errors
- Unknown relation
- Use of & in semgrex patterns is now illegal. It is…
- Parsing failed. Error:
- Couldn't parse + json
- Invalid txtGraph
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d8c3ddda40dccd48.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/GraphRelation.java:63
/**
* Returns <code>true</code> iff this <code>GraphRelation</code> holds between
* the given pair of nodes in the given semantic graph.
*/
abstract boolean satisfies(IndexedWord n1, IndexedWord n2, SemanticGraph sg);
/**
* For a given node and its root, returns an {@link Iterator} over the nodes
* of the semantic graph that satisfy the relation.
*/
abstract Iterator<IndexedWord> searchNodeIterator(IndexedWord node, SemanticGraph sg);
private GraphRelation(String symbol, String type, String name, String edgeName) {
this.symbol = symbol;
this.type = getPattern(type);
this.rawType = type;
this.edgeName = edgeName;
if (name != null && edgeName != null && !name.equals(edgeName)) {
throw new SemgrexParseException("GraphRelation had both = and ~ set, but the names were different! " + this.toString());
}
if (name != null) {
this.name = name;
} else {
this.name = edgeName;
}
}
private GraphRelation(String symbol, String type, String name) {
this(symbol, type, name, null);
}
private GraphRelation(String symbol, String type) {
this(symbol, type, null);
}
private GraphRelation(String symbol) {
this(symbol, null);View on GitHub (pinned to 1b7edd19c4)