stanfordnlp/CoreNLP · warning
Found a relation with a missing entity
Error message
Found a relation with a missing entity: ${p} What it means
KBPSemgrexExtractor.matches iterates SemgrexMatcher node matches and expects named nodes 'entity' and 'slot' in each pattern. If the 'entity' named node is absent from the matched graph, it warns with the pattern p and skips that match, treating it as a rule-authoring bug rather than a runtime failure.
Solutions
- Add the named node '=entity' to the Semgrex pattern (e.g. add "{...}=entity")
- Check the rule resources/patterns file for missing group names and fix the authoring
- Log the offending pattern and remove/disable it if it's obsolete
- Verify with a small Semgrex test that getNode("entity") returns non-null for intended matches
Example fix
// before
String p = "{tag:/NN.*/}=slot <nsubj {tag:/NN.*/}";
// after
String p = "{tag:/NN.*/}=entity <nsubj {tag:/NN.*/}=slot"; Defensive patterns
Strategy: validation
Validate before calling
SemgrexPattern p = SemgrexPattern.compile(pattern);
// ensure required named groups exist in the pattern string
if (!pattern.contains("=entity")) throw new IllegalArgumentException("pattern missing =entity: " + pattern); Try / catch
SemgrexMatcher m = p.matcher(graph);
while (m.find()) {
IndexedWord entity = m.getNode("entity");
if (entity == null) { log.warn("no entity for " + pattern); continue; }
// ...
} Prevention
- Always name both =entity and =slot groups in KBP Semgrex rules
- Unit-test each rule on annotated sample sentences
- Review rule resource files after edits for dropped group names
- Log and quarantine patterns that repeatedly produce null nodes
When it happens
Trigger: A Semgrex pattern used for KBP extraction that does not (or conditionally does not) bind the 'entity' named node, e.g. pattern string missing '{word:/.../}=entity' naming, and the matcher finds a hit without that node.
Common situations: Hand-written or edited Semgrex rules missing one of the required named groups; rules copied from other pipelines with different group names; optional groups that fail to bind on some matches.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Found a relation with a missing slot
- Invalid hypGraph
- Invalid txtGraph
- after W derivative, index() != x.length()
- An error occurred while testing the tagger.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f3a1ceea42e4daf7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/KBPSemgrexExtractor.java:121
tokens.get(i).setNER(input.subjectType.name);
}
}
for (int i : input.objectSpan) {
if ("O".equals(tokens.get(i).ner())) {
tokens.get(i).setNER(input.objectType.name);
}
}
for (SemgrexPattern p : rulesForRel) {
SemgrexMatcher n = p.matcher(graph);
while (n.find()) {
IndexedWord entity = n.getNode("entity");
IndexedWord slot = n.getNode("slot");
if (entity == null) {
// really this is a hideous bug, right? these rules
// should all have entity and slot set
logger.warn("Found a relation with a missing entity: " + p);
continue;
}
if (slot == null) {
logger.warn("Found a relation with a missing slot: " + p);
continue;
}
boolean hasSubject = entity.index() >= input.subjectSpan.start() + 1 && entity.index() <= input.subjectSpan.end();
boolean hasObject = slot.index() >= input.objectSpan.start() + 1 && slot.index() <= input.objectSpan.end();
if (hasSubject && hasObject) {
return p;
}
}
}
return null;
}
View on GitHub (pinned to 1b7edd19c4)