问题
I have the code below in a file named traversal.groovy
(which I call from the command line with gremlin -e traversal.groovy
):
// Begin traversal.groovy //
g = TinkerGraphFactory.createTinkerGraph()
v = g.v(1)
println v.outE.inV.name
// End traversal.groovy //
As you can see, it's very basic; but the output is not what I'm looking for. The output is
[StartPipe, OutEdgesPipe, InVertexPipe, PropertyPipe(name)]
When I run the same code in the gremlin command line, I get what I'm looking for...
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> v = g.v(1)
==>v[1]
gremlin> v.outE.inV.name
==>vadas
==>josh
==>lop
So, how do I access the information that I want that's somehow tucked away in [StartPipe, OutEdgesPipe, InVertexPipe, PropertyPipe(name)]
? Thanks!
回答1:
Thanks to stephen mallette for pointing me in the right direction. To simply print out the "name" property of each vertex in my traversal above, we can use sideEffect and iterate. The resulting code would look as follows:
// Begin traversal.groovy //
g = TinkerGraphFactory.createTinkerGraph()
v = g.v(1)
v.outE.inV.sideEffect{println it.name}.iterate()
// End traversal.groovy //
and the output would be:
vadas
josh
lop
回答2:
You likely just need to iterate your pipeline:
http://gremlindocs.com/#methods/pipe-next
println v.outE.inV.name.next()
来源:https://stackoverflow.com/questions/15508599/how-to-print-out-gremlin-pipe-traversal-results