mpollmeier / gremlin-scala

[unmaintained] Scala wrapper for Apache TinkerPop 3 Graph DSL
Apache License 2.0
482 stars 75 forks source link

Simple path finding #57

Closed omidb closed 9 years ago

omidb commented 9 years ago

It's not a Gremlin Scala specific question, I want to know what would be the simplest way to recursively find all path from node v1 that has out edge labeled of "friend". Basically exploring the whole graph from v1.

thanks

mpollmeier commented 9 years ago

can you provide a sample graph please? in a way that let's me explore it. What do you mean by recursively? if you just do g.v(1).outE("friend") that gives you the edges you describe..

omidb commented 9 years ago

I want to find all path available with "friend" edge: g.v(1).outE("friend").outE("friend")..... so the result will be all paths from v(1) which can be connected by this edge.

mpollmeier commented 9 years ago

So you want to find all paths like v1->e(friend)->v2, v1->e(friend)->v3, v1->e(friend)->e(friend)->v4? You can do that with a combination of jump (former loop) and path. Similar to http://gremlindocs.com/#recipes/shortest-path (which is Gremlin 2.x).

omidb commented 9 years ago

So the thing that I want is like this (it's gremlin way and I don't know the Tinkerpop3 way, in Tinkerpop3 loop has replaced by jump):

g = TinkerGraphFactory.createTinkerGraph() ==>tinkergraph[vertices:6 edges:6] gremlin> g.v(1).as('x').out('knows').loop('x'){it.loops<3}{true} ==>v[2] ==>v[4] gremlin> g.v(1).out.loop(1){it.object.id != "5" && it.loops < 6}.path

How would be the Scala gremlin way to write it? (a jump example would be very helpful as well)

mpollmeier commented 9 years ago

Interestingly I just prepared a similar example. Here's how it works at the moment, however one lesson from this is that I'll rename a few methods in GremlinScala, so stay tuned..

https://github.com/mpollmeier/gremlin-scala-examples/blob/master/neo4j_2.10/src/main/scala/ShortestPath.scala

omidb commented 9 years ago

Cool, it would be great if we have very general kind of big example graph and try to implement different methods on it in example project.

mpollmeier commented 9 years ago

moved it to https://github.com/mpollmeier/gremlin-scala-examples/blob/master/neo4j/src/main/scala/ShortestPath.scala