stanfordnlp/CoreNLP · error · RuntimeException
Unknown grammatical relation '
Error message
Unknown grammatical relation '
What it means
readDeps parses a dependency file where each line names a grammatical relation; the relation string is mapped to an EnglishGrammaticalRelations object (including conj_<x> handling). If no mapping is found (grel == null) the string is not a known English grammatical relation, so it throws with the offending relation name.
Solutions
- Correct the relation name in the input file to a valid EnglishGrammaticalRelations name.
- Match the reader to your data format — use the UniversalDependencies scoring variant or convert relations (e.g. nsubj:pass -> agent/auxpass equivalents) before scoring.
- Regenerate system output with a matching GrammaticalStructureFactory so relation names agree with the scorer.
Example fix
// before (input line) 5 obl:tmod 3 // after 5 tmod 3
Defensive patterns
Strategy: validation
Validate before calling
if (EnglishGrammaticalRelations.valueOf(depName) == null && !depName.startsWith("conj_")) { throw new IllegalArgumentException("unknown rel: " + depName); } Try / catch
try { scoring = new DependencyScoring(goldPath, ...); } catch (RuntimeException e) { if (e.getMessage().startsWith("Unknown grammatical relation")) { convertRelations(goldPath); scoring = new DependencyScoring(goldPath, ...); } } Prevention
- Generate dependency output with the same relation inventory the scorer expects
- Convert UD relation names to Stanford Dependencies before scoring
- Validate relation names in a preprocessing pass over the whole file
When it happens
Trigger: Scoring a dependency file whose relation column contains a relation not in EnglishGrammaticalRelations — e.g. SD-style names not matching the loaded grammar, universal-dependencies names (nsubj:pass, obl:*) against the non-UD relation set, typos, or relations from another language.
Common situations: Mixing Universal Dependencies output with English (Stanford Dependencies) scoring; custom relations added by a parser; scoring CoNLL data with short names (nsubj vs. subj) that this reader doesn't accept; version drift between tool output and library relation inventory.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ERROR: invalid direction type
- Unknown minimizer
- Unknown clique: " + clique
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/faac8336e903d7c3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/DependencyScoring.java:217
int commaSpace = line.indexOf(", ");
String depName = line.substring(0, firstParen);
String govName = line.substring(firstParen + 1, commaSpace);
String childName = line.substring(commaSpace+2, line.length() - 1);
GrammaticalRelation grel = GrammaticalRelation.valueOf(depName);
if (depName.startsWith("prep_")) {
String prep = depName.substring(5);
grel = EnglishGrammaticalRelations.getPrep(prep);
}
if (depName.startsWith("prepc_")) {
String prepc = depName.substring(6);
grel = EnglishGrammaticalRelations.getPrepC(prepc);
}
if (depName.startsWith("conj_")) {
String conj = depName.substring(5);
grel = EnglishGrammaticalRelations.getConj(conj);
}
if (grel == null) {
throw new RuntimeException("Unknown grammatical relation '" + depName+"'");
}
//Word govWord = new Word(govName.substring(0, govDash));
IndexedWord govWord = new IndexedWord();
govWord.setValue(normalizeNumbers(govName));
govWord.setWord(govWord.value());
//Word childWord = new Word(childName.substring(0, childDash));
IndexedWord childWord = new IndexedWord();
childWord.setValue(normalizeNumbers(childName));
childWord.setWord(childWord.value());
TypedDependency dep = new TypedDependencyStringEquality(grel, govWord, childWord);
deps.add(dep);
} catch (Exception e) {
breader.close();
throw new RuntimeException("Error on line "+breader.getLineNumber()+":\n\n"+e);
}
}
if (deps.size() != 0) {View on GitHub (pinned to 1b7edd19c4)