首页 文章

从路径打印/获取顶点值

提问于
浏览
0

刚刚开始使用gremlin .

打印出所有Vertex值都很好

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]]

Now am trying to print out the values in the path like ['Sales', 'Accounting'] instead of [v[25],v[28]]

还没有找到办法


已经尝试过 failed

  • Unfold:没有给我1-1映射

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

  • Path似乎是一个不同的数据类型,不支持.values()函数

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

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

l = []; g.V().....路径() . 填充(L)

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


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

1 回答

  • 3

    您可以使用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的玩具图形之一,通常用于这样的例子 . 您的输出看起来会有所不同,您可能希望使用 valueMap(true) 之外的其他内容来调整 by . TinkerPop documentation of the path step本身包含两个您可能想要查看的更高级的 path().by() 示例 .

相关问题