Printing/Fetching 来自路径的顶点值

Printing/Fetching Vertex values from a path

刚刚开始使用 gremlin。

打印出所有顶点值效果很好

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

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

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 映射

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

  2. 路径似乎是不同的数据类型,不支持 .values() 函数

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

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

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

  2. 找到了一个 java 的,但对我不起作用

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

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


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

您可以使用by step 来调制路径中的元素。例如,通过将 valueMap(true) 提供给 by,您可以获得顶点的属性,以及顶点标签及其 id:

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) 以外的其他东西。 TinkerPop documentation of the path step 本身包含两个更高级的 path().by() 示例,您可能想要查看。