-
Notifications
You must be signed in to change notification settings - Fork 238
SPARQL vs. Gremlin
okram edited this page Sep 13, 2010
·
26 revisions
SPARQL is a popular query language for RDF graphs. SPARQL is simple and intuitive, though it lacks various constructs for expressing any arbitrary graph query (e.g. looping and branching constructs). On the other hand, while Gremlin can be used to perform any arbitrary graph query, it lacks much of the intuitive and clean syntax made available by SPARQL. This section will discuss how to perform common SPARQL queries in Gremlin to help the user get a sense of how to query an RDF graph with Gremlin.
Here is a simple SPARQL query that will return all the people that vertex 1 knows
.
SELECT ?x WHERE {
tg:1 tg:knows ?x
}
In Gremlin, this is accomplished by a filtered path traversal out of vertex 1.
gremlin> .
==>v[http://tinkerpop.com#1]
gremlin> ./outE[@label=sail:ns($g,'tg:knows')]/inV
==>v[http://tinkerpop.com#4]
==>v[http://tinkerpop.com#2]