[英]Graph Traversal & Filtering with Gremlin using OrientDB
Group[code=a]->Choice[selected=true]
Group[code=a]->Choice[selected=false]
Group[code=a]->Choice[selected=false]
Group[code=b]->Choice[selected=false]
Group[code=b]->Choice[selected=false]
Group[code=c]->Choice[selected=false]
Group[code=c]->Choice[selected=true]
Given the above Vertices, I'm looking to query for Group Vertices, where a group does not have any Choice vertices, with a selected attribute as true. 给定上述顶点,我正在寻找一个组顶点,其中一个组没有任何Choice顶点,且所选属性为true。
Hence the result should return only Group b 因此,结果应仅返回b组
Group[code=b]
Any help is appreciated. 任何帮助表示赞赏。
Here's your graph - when asking questions about Gremlin it's always helpful to provide your sample data in this way: 这是您的图表-在询问有关Gremlin的问题时,以这种方式提供示例数据总是有帮助的:
graph = TinkerGraph.open()
g = graph.traversal()
g.addV('group').property('code','a').as('a').
addV('group').property('code','b').as('b').
addV('group').property('code','c').as('c').
addV('choice').property('selected',true).
addE('link').from('a').
addV('choice').property('selected',false).
addE('link').from('a').
addV('choice').property('selected',false).
addE('link').from('a').
addV('choice').property('selected',false).
addE('link').from('b').
addV('choice').property('selected',false).
addE('link').from('b').
addV('choice').property('selected',false).
addE('link').from('c').
addV('choice').property('selected',true).
addE('link').from('c').iterate()
One way to get the answer you want is to do a traversal like this: 获得所需答案的一种方法是进行如下遍历:
gremlin> g.V().hasLabel('group').
......1> where(__.not(out('link').has('selected',true))).
......2> values('code')
==>b
The above answer is for TinkerPop 3.x. 上面的答案适用于TinkerPop3.x。 In TinkerPop 2.x the pattern is the same.
在TinkerPop 2.x中,模式是相同的。 You would basically do:
您基本上会这样做:
g.V().has('label','group').filter{ it._().out('link').has('selected',true).hasNext() }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.