stanfordnlp/CoreNLP · error · UnknownVertexException
Unknown vertex
Error message
Unknown vertex
What it means
SemanticGraph.descendants(vertex) computes the transitive set of nodes governed by the given vertex via depth-first search, and throws UnknownVertexException if the vertex is not present in this graph. Each graph method validates membership first, so passing a node from a different (or rebuilt) graph always throws.
Solutions
- Check graph.containsVertex(vertex) before calling descendants
- Ensure the vertex came from the same graph instance (same parse), not another graph or a stale reference
- Use the Safe getter methods to re-resolve the vertex by index on the current graph
- Restructure code so vertex references do not outlive the graph they belong to
Example fix
// before
Set<IndexedWord> desc = graph.descendants(v);
// after
if (graph.containsVertex(v)) {
Set<IndexedWord> desc = graph.descendants(v);
} else { /* re-resolve by index or handle */ } Defensive patterns
Strategy: type-guard
Validate before calling
if (!graph.containsVertex(v)) { throw new IllegalStateException("vertex not in graph"); } Type guard
IndexedWord resolve(SemanticGraph g, IndexedWord maybeStale, int index) {
return g.containsVertex(maybeStale) ? maybeStale : g.getNodeByIndexSafe(index);
} Try / catch
try {
Set<IndexedWord> desc = graph.descendants(v);
} catch (UnknownVertexException e) {
// re-resolve v by index on the current graph
} Prevention
- Never reuse IndexedWord references across different SemanticGraph instances
- Re-resolve vertices by index after graph transformations
- Wrap vertex caches as (graph, vertex) pairs
- Check containsVertex before any traversal API
When it happens
Trigger: Calling descendants with an IndexedWord obtained from another SemanticGraph instance, or from a vertex whose backing document/graph was re-created, or after the node was removed from this graph.
Common situations: Comparing nodes across basic vs enhanced graphs; keeping IndexedWord references across pipeline stages that rebuild the parse; copy constructors that create a new graph while old vertex references are reused.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/ef5ee5ca9f5f7dda.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:701
public List<IndexedWord> getAllNodesByPartOfSpeechPattern(String pattern) {
Pattern p = Pattern.compile(pattern);
List<IndexedWord> nodes = new ArrayList<>();
for (IndexedWord vertex : vertexSet()) {
String pos = vertex.tag();
if ((pos == null && pattern == null) || pos != null && p.matcher(pos).matches()) {
nodes.add(vertex);
}
}
return nodes;
}
/**
* Returns the set of descendants governed by this node in the graph.
*
*/
public Set<IndexedWord> descendants(IndexedWord vertex) {
if (!containsVertex(vertex)) {
throw new UnknownVertexException(vertex, this);
}
// Do a depth first search
Set<IndexedWord> descendantSet = wordMapFactory.newSet();
descendantsHelper(vertex, descendantSet);
return descendantSet;
}
private void descendantsHelper(IndexedWord curr, Set<IndexedWord> descendantSet) {
if (descendantSet.contains(curr)) {
return;
}
descendantSet.add(curr);
for (IndexedWord child : getChildren(curr)) {
descendantsHelper(child, descendantSet);
}
}
/**View on GitHub (pinned to 1b7edd19c4)