TinkerPop:Gremlin再次造访过的边缘 [英] TinkerPop: Gremlin revisiting visited edges
本文介绍了TinkerPop:Gremlin再次造访过的边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
样本数据:
查询以创建样本数据
g.addV("Test1").property("title", "A")
g.addV("Test2").property("title", "B")
g.addV("Test3").property("title", "C")
g.addV("Test4").property("title", "D")
g.V().has("Test1", "title", "A").addE("rel").to(g.V().has("Test2", "title", "B"))
g.V().has("Test2", "title", "B").addE("rel").to(g.V().has("Test3", "title", "C"))
g.V().has("Test3", "title", "C").addE("rel").to(g.V().has("Test4", "title", "D"))
查询:
- 查找
A
与A
的连接方式
- Find how
A
is connected toA
预期答案:未连接
我的查询
g.V().has("Test1", "title", "A").as("nodes")
.repeat(both().as("nodes"))
.emit(hasLabel("Test1")).hasLabel("Test1")
.limit(25)
.project("val").by(select(all, "nodes").unfold().values("title").fold())
结果(limit 25
)
{'val': ['A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'D', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'C', 'D', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'C', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'C', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'A', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'B', 'A', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'C', 'D', 'C', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'C', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'C', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'A', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'D', 'C', 'D', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'D', 'C', 'B', 'C', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'D', 'C', 'B', 'A', 'B', 'A']}
{'val': ['A', 'B', 'C', 'D', 'C', 'B', 'C', 'D', 'C', 'B', 'A']}
好的,让我们尝试dedup
g.V().has("Test1", "title", "A").as("nodes")
.repeat(both().as("nodes").dedup())
.emit(hasLabel("Test1")).hasLabel("Test1")
.project("val").by(select(all, "nodes").unfold().values("title").fold())
结果
{'val': ['A', 'B', 'A']}
在A
和B
之间只有个边.那为什么格雷姆林在同一条边上横穿呢?我写错了查询吗?
There is exactly one edge between A
and B
. Then why is Gremlin traversing on the same edge? Am I writing the wrong query?
Cypher查询的行为方式似乎是正确的方式
How Cypher Query behaves seems to be the correct way to be
MATCH p=((n:Test1)-[*]-(m:Test1)) RETURN p
Gremlin Server版本:3.3.1
推荐答案
所有您想要的都是非循环路径:
Looks like all you want is non-cyclic paths:
g.V().has("Test1", "title", "A").
repeat(both().simplePath()).
until(hasLabel("Test1")).
path().
by("title")
这篇关于TinkerPop:Gremlin再次造访过的边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文