这是您的图表 - 在询问有关 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()
获得所需答案的一种方法是进行如下遍历:
gremlin> g.V().hasLabel('group').
......1> where(__.not(out('link').has('selected',true))).
......2> values('code')
==>b
以上答案适用于 TinkerPop 3.x。在 TinkerPop 2.x 中,模式是相同的。你基本上会这样做:
g.V().has('label','group').filter{ it._().out('link').has('selected',true).hasNext() }