Hi,
I just had an idea.
So, in Gremlin, you can build a custom DSL by defining your own TraversalSource and Traversals. For instance:
social = graph.traversal(SocialTraversalSource.class);
social.person(“marko”).knows(well).inGroup(“YMCA”)
Now, this works great for DSL’s that are embedded in the developer’s native language — i.e. monoids through fluent composition. However, lets say you want to have SPARQL support. Well, there are two ways to do this where the second is “better,” but requires the first.
1. Develop a SPARQL parser that generates Gremlin bytecode and generate the GraphTraversal from the bytecode.
2. Create a SPARQLTraversalSource and SPARQLTraversal.
- This is the new idea.
sparql = graph.traversal(SPARQLTraversalSource.class);
sparql.query(“SELECT ?x from ?x knows ?y”)
Now query(String) would parse the SPARQL statement and generate Gremlin bytecode (#1 above) and insert the bytecode into the SPARQLTraversal. With this model, the native language of the developer doesn’t need to parse SPARQL. You can have Jena (lets say) on the server side doing all the SPARQL->GremlinBytecode translation. Thus, in Gremlin-Python, the user would simply do:
sparql = graph.traversal(SparqlTraversalSource)
sparql.query(“SELECT ?x WHERE { ?x knows ?y }”)
Tada! Language agnostic SPARQL.
And best of all, if SPARQLTraversal extends GraphTraversal, you can then do:
sparql = graph.traversal(SparqlTraversalSource.class)
sparql.query(“SELECT ?x WHERE { ?x knows ?y }”).out(“wrote”).count()
Marko.