Thanks for this Marko. The original Python OGM mogwai included a limited subset of this sort of functionality that allowed the user to create traversals (always with a start node) using an interface that mirrored the Blueprints API. In my initial port to TP3 (Goblin) [1] , I changed this to class `V` [3] and did a minimum refactor to get everything working with the new stack. Currently, this part of the library is under review (both the API and the internals); maybe we will move towards model-3 as you suggest. However, I'm not sure if this will be a top priority, as there are other bits of functionality we are working on currently.
Anyway, I thought you may like to know. I also think that any resources you provide for the community are definitely welcome! Thanks to the whole TinkerPop team! 1. http://goblin.readthedocs.org/en/latest/index.html 2. http://goblin.readthedocs.org/en/latest/usage.html#the-v-ertex-centric-query-api Btw, a real release of Goblin is coming this week. I'll announce on the lists... Best, Dave On Tue, Apr 12, 2016 at 10:37 AM, Marko Rodriguez <okramma...@gmail.com> wrote: > Hello everyone, > > Please see the section entitled "Host Language Embedding" here: > http://www.planettinkerpop.org/#gremlin (3 sections down) > > When I was writing up this section, I noticed that most of the language > drivers that are advertised on our homepage > (http://tinkerpop.incubator.apache.org/#graph-libraries) know how to talk to > Gremlin Server via web sockets, REST, etc., but rely on the user to create a > String of their graph traversal and submit it. For instance, here is a > snippet from the Gremlin-PHP documentation: > > $db = new Connection([ > 'host' => 'localhost', > 'graph' => 'graph', > 'username' => 'pomme', > 'password' => 'hardToCrack' > ]); > //you can set $db->timeout = 0.5; if you wish > $db->open(); > $db->send('g.V(2)'); > //do something with result > $db->close(); > > $db->send(String) is great, but it would be better if the user didn't have to > leave PHP. > > Please see this ticket: > https://issues.apache.org/jira/browse/TINKERPOP-1232 > > I think for non-JVM languages, it would be nice if these drivers (PHP, > JavaScript, Python, etc.) didn't require the user to explicitly create > Gremlin-XXX Strings, but instead either used JINI or model-3 in the ticket > above. Lets look at model-3 as I think its the easiest and more general. > > For instance, they would have a class in their native language that would > mirror the GraphTraversal API. *** I don't know any other languages well > enough, so I'm just going to do this in Groovy :), hopefully you get the > generalized point. *** > > public class Test { > > String s; > > public Test(final String source) { > s = source; > } > > public Test() { > s = ""; > } > > public Test V() { > s = s + ".V()"; > return this; > } > > public Test outE(final String label) { > s = s + ".outE(\"${label}\")"; > return this; > } > > public Test repeat(final Test test) { > s = s + ".repeat(${test.toString()})"; > return this; > } > > public String toString() { > return s; > } > } > > Then, via fluency (function composition) and nesting, you could generate a > Gremlin-Groovy (or which ever ScriptEngine language) traversal String in the > backend. > > gremlin> g = new Test("g"); > ==>g > gremlin> g.V().outE("knows") > ==>g.V().outE("knows") > gremlin> > gremlin> g = new Test("g"); > ==>g > gremlin> g.V().repeat(new Test().outE("knows")) > ==>g.V().repeat(.outE("knows")) > gremlin> > > From there, that String is then submitted as you normally do with your > driver. For instance, with Gremlin-PHP, via $db->send(String). > > Of course, if your driver is already on a JVM language, there is no reason to > do this (e.g. Gremlin-Scala), but if you are not on the JVM, this gives the > user host language embedding and a more natural "look and feel." Moreover, if > your language doesn't use "dot notation," you would use the natural idioms of > your language. > > $g->V->outE("knows") > > If anyone is interested in updating their non-JVM language driver to use this > model, I would like to write a blog post about it. Or perhaps, a tutorial for > for language designers. > > Thoughts?, > Marko. > > http://markorodriguez.com > -- David M. Brown R.A. CulturePlex Lab, Western University