【问题标题】:Printing/Fetching Vertex values from a path从路径打印/获取顶点值
【发布时间】:2018-08-19 02:52:13
【问题描述】:

刚刚开始使用 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> gV().hasLabel('Process').repeat(both().simplePath()).until(hasLabel('Process')).dedup().path().unfold().values () ==>现金处理 ==>会计 ==>现金处理 ==>销售 ==>销售 ==>营销 ==>销售 ==>现金处理

  2. 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

  1. 尝试了以下谷歌搜索并没有得到答案

  2. here 找到一个适用于 java 但对我不起作用

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

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


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

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    您可以使用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() 示例,您可能想查看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      相关资源
      最近更新 更多