SPARQL Query
SELECT ?person ?greatgrandfather
WHERE {
?person :hasName "John" .
?person :hasFather ?father .
?father :hasFather ?grandfather .
?grandfather :hasFather ?greatgrandfather .
}
WHERE {
?person :hasName "John" .
?person :hasFather ?father .
?father :hasFather ?grandfather .
?grandfather :hasFather ?greatgrandfather .
}
How It Works
The query engine scans all triples for :hasName "John", binding each match to ?person. Then it follows :hasFather edges three times, binding each hop to a new variable. The traversal is deterministic and exact — it requires a literal match on "John", not approximate similarity.
Traversal Steps
Results
Click "Run Query" to execute the SPARQL query
The Limitation
SPARQL finds great-grandfathers perfectly — but only for people named exactly "John". It won't match "Jean", "Johan", "Juan", or "Jon" unless you write separate queries for each. Graph databases have no concept of semantic similarity. If the data uses "Jonathan" instead of "John", the query returns nothing.