【问题标题】:TinkerPop Gremlin Repeat until no more edgesTinkerPop Gremlin 重复直到没有边缘
【发布时间】:2020-07-12 08:12:53
【问题描述】:

我想从一个顶点开始,沿着向外的边缘,直到我到达一个“叶子”顶点,没有更多的向外边缘。

我试过了

g.V(2).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count() == 0)

直到我发现的所有示例都通过“has”或类似测试顶点上的属性时,我才知道要传递什么。

我正在尝试使用 Gremlin 控制台,但还需要它在 java 应用程序中工作。

示例图:

graph = TinkerGraph.open()
g = graph.traversal()


a1 = g.addV("acc").property(id, 1).next()
a2 = g.addV("acc").property(id, 2).next()
a3 = g.addV("acc").property(id, 3).next()
a4 = g.addV("acc").property(id, 4).next()
a5 = g.addV("acc").property(id, 5).next()

sfid_a = g.addV("sfid").property(id, "a").next()
sfid_b = g.addV("sfid").property(id, "b").next()

cust_x = g.addV("cust").property(id, "x").next()
cust_y = g.addV("cust").property(id, "y").next()

ind = g.addV("region").property(id, "in").next()
usa = g.addV("region").property(id, "us").next()

aws = g.addV("business").property(id, "aws").next()

g.addE('has_payer').from(a2).to(a4)

g.addE('has_sfid').from(a5).to(sfid_b)
g.addE('has_sfid').from(a3).to(sfid_a)
g.addE('has_sfid').from(a4).to(sfid_a)


g.addE('has_cust').from(sfid_b).to(cust_x)
g.addE('has_cust').from(sfid_a).to(cust_x)
g.addE('has_cust').from(cust_x).to(cust_y)
g.addE('has_cust').from(a1).to(cust_y)


g.addE('has_business').from(a1).to(aws)
g.addE('has_business').from(a2).to(aws)
g.addE('has_business').from(a3).to(aws)
g.addE('has_business').from(a4).to(aws)
g.addE('has_business').from(a5).to(aws)


g.addE('has_region').from(a1).to(ind)
g.addE('has_region').from(a1).to(usa)
g.addE('has_region').from(a2).to(ind)
g.addE('has_region').from(a2).to(usa)
g.addE('has_region').from(a3).to(ind)
g.addE('has_region').from(a4).to(usa)
g.addE('has_region').from(a5).to(ind)
g.addE('has_region').from(a5).to(usa)

【问题讨论】:

    标签: gremlin tinkerpop


    【解决方案1】:

    看来我可以使用“is”步骤来过滤标量

    g.V(2).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(0))
    g.V(2).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(gt(5)))
    

    【讨论】:

    • 大多数图表应该对此进行优化,但是当使用已知最大值执行count() 时,最好明确包含限制 - outE().limit(6).count().is(gt(5)) - 在这种情况下,您只需要 6 条边来证明 gt(5)count() 最好是 6 而不是 60、600、6000 等。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    相关资源
    最近更新 更多