TinkerPop Gremlin 重复直到没有边缘
TinkerPop Gremlin Repeat until no more edges
我想从一个顶点开始,沿着向外的边,直到我到达一个“叶”顶点,没有更多的外边。
我试过了
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)
看来我可以使用“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)))
我想从一个顶点开始,沿着向外的边,直到我到达一个“叶”顶点,没有更多的外边。
我试过了
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)
看来我可以使用“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)))