从路径打印/获取顶点值 [英] Printing/Fetching Vertex values from a path

查看:87
本文介绍了从路径打印/获取顶点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用葛瑞姆林.

打印出所有的Vertex值都很好

Printing out all the Vertex values worked out fine

gremlin> g.V().values()
==>testing 2
==>Cash Processing
==>Sales
==>Marketing
==>Accounting

我能够找到我的顶点之间的所有直接连接的路径.

I was able to find all the directly connected path between my Vertices.

gremlin> g.V().hasLabel('Process')
.repeat(both().simplePath())
.until(hasLabel('Process'))
.dedup().path()
==>[v[25],v[28]]
==>[v[25],v[26]]
==>[v[26],v[27]]
==>[v[26],v[25]]

现在正在尝试打印路径中的值,例如['Sales','Accounting'],而不是[v [25],v [28]]

还无法找到一种方法

已经尝试,并且失败

  1. 展开:没有让我1-1映射

  1. Unfold: Does not get me 1-1 mapping

gremlin> gV().hasLabel('Process').repeat(both().simplePath()).until(hasLabel('Process')).dedup().path().unfold().values () ==>现金处理 ==>会计 ==>现金处理 ==>销售 ==>销售 ==>行销 ==>销售 ==>现金处理

gremlin> g.V().hasLabel('Process').repeat(both().simplePath()).until(hasLabel('Process')).dedup().path().unfold().values() ==>Cash Processing ==>Accounting ==>Cash Processing ==>Sales ==>Sales ==>Marketing ==>Sales ==>Cash Processing

路径似乎是另一种数据类型,并且不支持.values()函数

Path seems to be of a different data-type and does not support .values() function

gremlin> g.V().hasLabel('Process') .repeat(both().simplePath()) .until(hasLabel('Process')) .dedup().path().values()

gremlin> g.V().hasLabel('Process') .repeat(both().simplePath()) .until(hasLabel('Process')) .dedup().path().values()

org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath无法转换为org.apache.tinkerpop.gremlin.structure.Element

org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath cannot be cast to org.apache.tinkerpop.gremlin.structure.Element

  1. 尝试了以下Google搜索,但没有得到答案

  1. Tried the following google searches and didnt get the answer

  • gremlin print a path
  • gremlin get values in a path
  • and few more word twisting

此处找到了一个适用于Java但对我无效的

Found one at here that was for java but that didnt work for me

l = []; g.V()..... path().fill(l)

l = []; g.V().....path().fill(l)

(但无法创建列表,无法设置只读属性:类的列表:org.apache.tinkerpop.gremlin.structure.VertexProperty $ Cardinality )

(but cant create list, Cannot set readonly property: list for class: org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality )

我已经在Gremlin控制台上运行它(正在运行./gremlin.sh)

推荐答案

您可以使用

You can use the by step to modulate the elements inside the path. For example by supplying valueMap(true) to by you get the properties of the vertices, together with the vertex labels and their ids:

gremlin> g.V().repeat(both().simplePath()).times(1).dedup().path().by(valueMap(true))
==>[[id:1,name:[marko],label:person,age:[29]],[id:3,name:[lop],lang:[java],label:software]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:2,name:[vadas],label:person,age:[27]]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:4,name:[josh],label:person,age:[32]]]
==>[[id:2,name:[vadas],label:person,age:[27]],[id:1,name:[marko],label:person,age:[29]]]
==>[[id:3,name:[lop],lang:[java],label:software],[id:6,name:[peter],label:person,age:[35]]]
==>[[id:4,name:[josh],label:person,age:[32]],[id:5,name:[ripple],lang:[java],label:software]]

我使用了现代图形,它是TinkerPop的玩具图形之一,通常用于此类示例.您的输出看起来会有些不同,并且您可能想对by调制器使用除valueMap(true)之外的其他内容. path步骤 TinkerPop文档本身包含另外两个您可能想检出的path().by()的高级示例.

I used the modern graph which is one of TinkerPop's toy graphs that are often used for such examples. Your output will look a bit different and you may want to use something else than valueMap(true) for the by modulator. The TinkerPop documentation of the path step itself contains two more advanced examples for path().by() that you might want to check out.

这篇关于从路径打印/获取顶点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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