Neptune 图遍历,使用最后一个顶点的动态计算值来选择传出边以进行进一步遍历

问题描述 投票:0回答:1

这是我的图表:

enter image description here

这是图形构建代码:

// backslashes included so the code can be copy and pasted into gremlin console

g\
.addV("Person").property(T.id, "A").as("a")\
.addV("Person").property(T.id, "B").as("b")\
.addV("Person").property(T.id, "C").as("c")\
.addV("Person").property(T.id, "D").as("d")\
.addV("Person").property(T.id, "E").as("e")\
.addV("Right").property(T.id, "1").property(set, "types", 1).property(set, "types", 2).as("r1")\
.addV("Right").property(T.id, "2").property(set, "types", 2).property(set, "types", 3).as("r2")\
.addV("Right").property(T.id, "3").property(set, "types", 4).property(set, "types", 5).as("r3")\
.addV("Right").property(T.id, "4").property(set, "types", 2).as("r4")\
.addE("receives").from("r1").to("a").property(T.id, "a")\
.addE("receives").from("b").to("r1").property(T.id, "b")\
.addE("receives").from("r2").to("b").property(T.id, "c")\
.addE("receives").from("r3").to("b").property(T.id, "d")\
.addE("receives").from("d").to("r3").property(T.id, "e")\
.addE("receives").from("c").to("r2").property(T.id, "f")\
.addE("receives").from("r4").to("c").property(T.id, "g")\
.addE("receives").from("e").to("r4").property(T.id, "h")

我的要求是从 A 到 E 遍历图形,检查 Right 顶点的 types 属性是否沿途有交集 - 如果类型与上一步的类型相交,则选择边进行遍历,否则停止,忽略 Right where类型不相交。

这是我迄今为止尝试过的:

g.withSack([2]).V("A").
repeat(
  inE("receives").outV().
    filter(values("types").fold().intersect(sack()).unfold().aggregate("inter")).
  inE("receives").outV().as("current").
  choose(inE().hasLabel("receives").count().is(0), select("current"), inE("receives").
    outV().filter(values("types").fold().intersect(select("inter")).unfold()).inE("receives").outV()).
  sack(assign).by(select("inter"))).
until(inE().hasLabel("receives").count().is(0))

此查询有问题:

  1. 麻袋的初始值是硬编码的 - 当我尝试将其初始化到 A 的右侧(右 1)时,intersect() 函数不再起作用

    g.withSack([]).V("A").as("开始").inE("接收").outV() .sack(分配).by(values("类型").fold()) .select("开始").重复(

  2. values("types").fold() 折叠所有节点的类型(在边界上 - 这就是我们所说的吗?)并且我想评估每个本地步骤的类型,我是否需要考虑“本地”以某种方式

我可以使用 Neptune 中的 Gremlin 的交集来实现这种动态的、步进范围的过滤吗?

gremlin tinkerpop amazon-neptune
1个回答
0
投票

withSack() 的工作原理是在重复结束时收集遍历结果,因此不适合保存动态计算的重复之间的每次遍历值。

我能让它按预期工作的唯一方法是使用“联合”手动重复内部遍历 - 所以我必须知道遍历可能需要多深。

这远非理想,如果有更好的方法,我会邀请领域专家对此答案发表评论。

© www.soinside.com 2019 - 2024. All rights reserved.