stanfordnlp/CoreNLP · error · ParseException
Unknown relation
Error message
Unknown relation
What it means
GraphRelation.createRelation throws java.text.ParseException when the relation symbol (reln) is not one of the known Semgrex relation operators (>, >++, <, <<, ==, ~, etc.). The symbol is checked against a whitelist via isKnownRelation before dispatching to the relation class.
Solutions
- Correct the relation symbol to a valid Semgrex operator (>, <, <<, >>, ==, ~, <<#, etc.)
- Check the Semgrex documentation for the supported relation list
- If porting from Tregex, translate each relation to its Semgrex equivalent
Example fix
// before
String pattern = "{word:dog} => {word:cat}";
// after
String pattern = "{word:dog} > {word:cat}"; Defensive patterns
Strategy: validation
Validate before calling
Set<String> known = Set.of(">",">>",">++","<","<<","<<#",">>","<<:",">>:","==",".","~");
if (reln != null && !known.contains(reln)) throw new IllegalArgumentException("Unknown relation " + reln); Try / catch
try { GraphRelation r = GraphRelation.createRelation(reln, type, name, edgeName); } catch (ParseException e) { log.error("Unknown Semgrex relation '" + reln + "'"); } Prevention
- Verify relation symbols against the Semgrex operator reference before writing patterns
- Translate Tregex relations explicitly rather than reusing them in Semgrex
- Add pattern validation tests covering every relation used in configs
When it happens
Trigger: Calling GraphRelation.createRelation with an unrecognized reln string, e.g. a typo like '=>', 'gov', or an operator from a different grammar (Tregex-style) pasted into a Semgrex pattern.
Common situations: Hand-written Semgrex queries with mistyped relation operators; porting Tregex patterns to Semgrex without translating relations; config or query files edited manually.
Related errors
- GraphRelation had both = and ~ set, but the names were…
- 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/3e37d0ed3decfe9f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/GraphRelation.java:1460
reln.equals(">>") || reln.equals("<<") ||
reln.equals("<>") ||
reln.equals("@") || reln.equals("==") ||
reln.equals("$+") || reln.equals("$++") ||
reln.equals("$-") || reln.equals("$--") ||
reln.equals(".") || reln.equals("..") ||
reln.equals("-") || reln.equals("--") ||
reln.equals(">++") || reln.equals(">--") ||
reln.equals("<++") || reln.equals("<--"));
}
public static GraphRelation getRelation(String reln,
String type,
String name,
String edgeName) throws ParseException {
if (reln == null && type == null)
return null;
if (!isKnownRelation(reln)) {
throw new ParseException("Unknown relation " + reln);
}
switch (reln) {
case ">":
return new GOVERNOR(type, name, edgeName);
case ">++":
return new GOVERNOR_RIGHT(type, name, edgeName);
case ">--":
return new GOVERNOR_LEFT(type, name, edgeName);
case "<":
return new DEPENDENT(type, name, edgeName);
case "<++":
return new DEPENDENT_RIGHT(type, name, edgeName);
case "<--":
return new DEPENDENT_LEFT(type, name, edgeName);
case "<>":
return new CONNECTED(type, name, edgeName);
}
if (edgeName != null) {View on GitHub (pinned to 1b7edd19c4)