如何输出Gremlin管道/遍历结果 [英] How to print out Gremlin pipe / traversal results

查看:463
本文介绍了如何输出Gremlin管道/遍历结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将下面的代码放在一个名为 traversal.groovy (我从命令行调用 gremlin -e traversal.groovy ):

  //开始traversal.groovy // 

g = TinkerGraphFactory .createTinkerGraph()
v = gv(1)

println v.outE.inV.name

// end traversal.groovy //

正如您所看到的,这非常基本;但是输出不是我想要的。输出是

pre $ [StartPipe,OutEdgesPipe,InVertexPipe,PropertyPipe(name)]



当我在gremlin命令行中运行相同的代码时,我得到了我正在寻找的内容...

  gremlin> g = TinkerGraphFactory.createTinkerGraph()
==> tinkergraph [vertices:6 edges:6]
gremlin> v = g.v(1)
==> v [1]
gremlin> v.outE.inV.name
==> vadas
==> josh
==> lop
中[StartPipe,OutEdgesPipe,InVertexPipe,PropertyPipe(name)] C $ C>?感谢!

解决方案

感谢 stephen mallette 指向正确的方向。为了简单地在我的遍历中打印出每个顶点的name属性,我们可以使用 sideEffect < a>和迭代。结果代码如下所示:

  //开始traversal.groovy // 

g = TinkerGraphFactory .createTinkerGraph()
v = gv(1)

v.outE.inV.sideEffect {println it.name} .iterate()

//结束遍历.groovy //

并且输出结果为:

  vadas 
josh
lop


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!

解决方案

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

这篇关于如何输出Gremlin管道/遍历结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆