格林姆林:如何找到没有特定边的顶点? [英] Gremlin: How do you find vertices without a particular edge?
问题描述
我一直在研究Gremlin图形语言,它看起来非常强大.但是,在研究如何根据需求进行评估时,我遇到了一个我似乎无法完成的案例.
I've been looking at the Gremlin graph language, and it appears very powerful. However, whilst running through what it can do to evaluate it against requirements, I came across a case that I can't seem to complete.
假设Gremlin已启动,并使用其示例数据库:
Assuming Gremlin is started, and using its example database:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
...
gremlin> g.V.out('knows')
==>v[2]
==>v[4]
因此,这显示了具有已知"边缘的顶点.
So this shows vertices that have an edge of 'knows'.
但是,我想查找不具有已知"边缘的顶点.像这样:
However, I want to find vertices that do not have edges of 'knows'. Something like:
gremlin> g.V.outNot('knows')
==>v[3]
==>v[5]
==>v[6]
如何找到这些顶点?
(编辑以使输出正确)
推荐答案
我以几种方式解释了这个问题,但这也许正是您所追求的.一种方法是:
I interpret this question several ways, but perhaps this is what you are after. One way would be to do:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V.outE.hasNot('label','knows')
==>e[9][1-created->3]
==>e[12][6-created->3]
==>e[10][4-created->5]
==>e[11][4-created->3]
gremlin> g.V.outE.hasNot('label','knows').inV
==>v[3]
==>v[3]
==>v[5]
==>v[3]
请注意,标签和ID均被识别为属性:
Note that label and id are both recognized as properties:
gremlin> g.V.has('id',"1")
==>v[1]
gremlin> g.E.map("label","id")
==>{id=10, label=created}
==>{id=7, label=knows}
==>{id=9, label=created}
==>{id=8, label=knows}
==>{id=11, label=created}
==>{id=12, label=created}
考虑此问题的另一种方法是找到没有知道"边的顶点列表:
Another way to consider this question would be to find a list of vertices that don't have a "knows" edge:
gremlin> g.V.filter{!it.bothE('knows').hasNext()}
==>v[3]
==>v[6]
==>v[5]
这篇关于格林姆林:如何找到没有特定边的顶点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!