stanfordnlp/CoreNLP · error · ParseException
Unrecognized compound relation
Error message
Unrecognized compound relation
What it means
This ParseException is the final else branch of the numeric getRelation(String,String,int,String,String) overload: the relation is neither '>>' nor '<<' nor any known relation, so it is an unrecognized compound relation and the reln string plus the relation type are reported. It means the parser encountered an operator string that does not exist in Semgrex at all while a numeric argument was present.
Solutions
- Check the relation spelling against GraphRelation.isKnownRelation ('>', '<', '>>', '<<', '<>', '@', '==', '$+', '$++', '$-', '$--', '.', '..', '-', '--', '>++', '>--', '<++', '<--').
- If a count is intended, only '>>' and '<<' accept it; fix the operator to one of those.
- Upgrade the CoreNLP version if the relation was added in a newer release.
- Print the full pattern and locate the malformed operator near the numeric argument.
Example fix
// before
GraphRelation r = GraphRelation.getRelation("<>>", null, 2, name, null); // throws
// after
GraphRelation r = GraphRelation.getRelation(">>", null, 2, name, null); // corrected operator Defensive patterns
Strategy: validation
Validate before calling
static final Set<String> KNOWN = Set.of(">", "<", ">>", "<<", "<>", "@", "==",
"$+", "$++", "$-", "$--", ".", "..", "-", "--", ">++", ">--", "<++", "<--");
if (!KNOWN.contains(reln)) {
throw new IllegalArgumentException("Unrecognized relation: " + reln);
} Try / catch
try {
GraphRelation r = GraphRelation.getRelation(reln, type, num, name, null);
} catch (ParseException e) {
if (e.getMessage().startsWith("Unrecognized compound relation")) {
throw new IllegalArgumentException("Invalid Semgrex operator in pattern: " + reln, e);
}
} Prevention
- Whitelist relation strings against isKnownRelation before invoking getRelation.
- Fail fast in pattern parsers on unrecognized operator tokens with a clear user-facing message.
- When copying patterns across tools/versions, re-validate each operator against the target CoreNLP version.
When it happens
Trigger: Calling getRelation(">>*", type, 2, name, null), getRelation("~obj", type, 1, name, null), or any misspelled/unknown operator with the int overload. Parsing a Semgrex pattern containing a malformed operator such as '<>>' routed into the compound relation path.
Common situations: Typos in hand-written Semgrex patterns; using relation syntax from a different version or a different library (e.g. tregex-style operators); copy-pasted patterns from documentation of newer CoreNLP versions into older jars.
Related errors
- Relation does not allow for named edges
- Relation not handled by getRelation
- Relation does not use numeric arguments
- Invalid txtGraph
- Invalid hypGraph
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/bc92a1d87c72d63f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/GraphRelation.java:1531
public static GraphRelation getRelation(String reln,
String type,
int num,
String name,
String edgeName) throws ParseException {
if (edgeName != null) {
throw new ParseException("Relation " + reln + " does not allow for named edges");
}
if (reln == null && type == null)
return null;
if (reln.equals(">>"))
return new LIMITED_GRANDPARENT(type, name, num, num);
else if (reln.equals("<<"))
return new LIMITED_GRANDKID(type, name, num, num);
else if (isKnownRelation(reln))
throw new ParseException("Relation " + reln +
" does not use numeric arguments");
else //error
throw new ParseException("Unrecognized compound relation " + reln + " "
+ type);
}
public static GraphRelation getRelation(String reln,
String type,
int num, int num2,
String name,
String edgeName) throws ParseException {
if (edgeName != null) {
throw new ParseException("Relation " + reln + " does not allow for named edges");
}
if (reln == null && type == null)
return null;
if (reln.equals(">>"))
return new LIMITED_GRANDPARENT(type, name, num, num2);
else if (reln.equals("<<"))
return new LIMITED_GRANDKID(type, name, num, num2);
else if (isKnownRelation(reln))View on GitHub (pinned to 1b7edd19c4)