Closed albertotonon closed 8 years ago
Sounds like you literally translated a gremlin groovy traversal. The problem is that you are loosing the types on the way because you labelled the steps with a String (e.g. "e0") - after the select
step the compiler does not know the e0 is a Vertex, and the both
step only works on vertices. This is to prevent you from writing an invalid traversal :)
To fix that problem you can use a StepLabel as below.
val E0 = StepLabel[Vertex]("e0")
val E1 = StepLabel[Vertex]("e1")
graph.V.as(E0).out("Feedbacks").as(E1).select(E0).repeat(_.both("Meets"))
You'll still have to work on the until
part - I'd encourage you to have a look at the shortest path example here: http://www.michaelpollmeier.com/2014/12/27/gremlin-scala-shortest-path/
Pro tip: use the nice DSL for adding vertices and edges:
val Name = Key[String]("name")
val e0 = graph + ("User", (Name -> "e0"))
val e1 = graph + ("User", (Name -> "e1"))
...
e0 --- "Feedbacks" --> e2
...
Can you describe in plain english what you're trying to achieve with your traversal?
Thanks, Michael, for your advice. Indeed it was taken from a gremlin groovy traversal, this one to be precise.
My goal is to find all the vertices directly connected by a 'Feedbacks' edge that are also connected by a 'Meets' path (with one or more steps).
I read your example and modified my traversal, now it looks like this:
val e0select = StepLabel[Vertex]("e0")
val e1select = StepLabel[Vertex]("e1")
graph.V.as(e0select)
.out("Feedbacks").as(e1select)
.select(e1select)
.repeat(_.out("Meets")).until(_.is(e1select)))
.path()
and now the code gets compiled successfully.
I used _.is()
inside the until()
step since I noticed you did something similar in your shortest path example, and replaced the both()
step inside the repeat()
with out()
.
Moreover, when testing I removed the e4 --> e0 edge to avoid having cycles, and used out()
instead of both()
inside the repeat()
step.
Nevertheless the traversal does not return the right result ([[e2, e4]]). I guess I haven't completely understood how to use StepLabels in traversals (specifically in comparisons) and I haven't found any example for that. Will you elucidate this matter, if you have time?
I've got what I wanted by using
graph.V.as(e0select).out("Feedbacks").as(e1select).select(e0select).repeat(_.out("Meets")).until(_.where(P.eq("e1"))).path().by("name").toList()
Thanks for helping and sorry for disturbing for such a trivial matter.
Some documentation on StepLabel
s would be useful, though :)
Cheers!
btw there is (and was) documentation on StepLabel
s in the readme - any ideas on how to improve that?
Hello everybody, thanks for the project: the DSL is awesome!
Unfortunately I have an issue when I try to compile the code reported below. The compiler stops executing the last instruction and tells me that "both is not a member of gremlin.scala.GremlinScala[Any, shapeless.HNil]. The issue persists if I use a TinkerGraph.
Does anybody have any idea what's going wrong?