简体   繁体   English

通过边缘标签过滤Gremlin遍历

[英]Filtering a Gremlin Traversal by edge label

I am trying to use Gremlin to traverse outwards from a starting node to all connected nodes within X degrees of connection. 我正在尝试使用Gremlin从X的连接度内的起始节点向外遍历所有连接的节点。 The direction of the connection does not matter, so I am using the both() function. 连接的方向无关紧要,所以我正在使用both()函数。 I also want to be able to prevent the traversal from crossing edges with specific labels. 我还希望能够防止遍历与特定标签的边缘交叉。 Here's a sample graph. 这是一个示例图。

gremlin> g.addV().property(id,1).as('1').
......1>   addV().property(id,2).as('2').
......2>   addV().property(id,3).as('3').
......3>   addV().property(id,4).as('4').
......4>   addV().property(id,5).as('5').
......5>   addV().property(id,6).as('6').
......6>   addV().property(id,7).as('7').
......7>   addE('edge1').from('1').to('2').
......8>   addE('edge2').from('1').to('3').
......9>   addE('edge2').from('2').to('4').
.....10>   addE('edge3').from('3').to('5').
.....11>   addE('edge3').from('4').to('6').
.....12>   addE('edge4').from('7').to('6').iterate()

The traversal that I have so far looks like this: 到目前为止,遍历如下所示:

gremlin> g.V(1).
......1>   repeat(both().filter(not(inE('edge3')))).
......2>   times(4).
......3>   emit().
......4>   simplePath().
......5>   dedup()

However this is not quite what I am looking for. 但是,这并不是我想要的。 I want something which will actually prevent the traverser from hitting a vertex if it has to cross the specified edge. 我想要某种东西,如果它必须穿过指定的边缘,它将实际上阻止遍历器碰到顶点。 My current implementation filters vertices which have the incoming edge, but in some cases I may still want that vertex to appear in the results if the traverser crossed a different edge to get there. 我当前的实现对具有传入边的顶点进行过滤,但是在某些情况下,如果遍历器越过另一条边到达顶点,我仍然希望该顶点出现在结果中。

Does this make sense? 这有意义吗? In short, I am trying to specifically filter on an edge rather than on a vertex's relationship to its edges. 简而言之,我试图专门过滤边缘而不是顶点与其边缘的关系。

I think I followed what you were saying, couldn't you just use bothE() and filter those edges while traversing them: 我想我遵循了您的意思,您不能只使用bothE()并在遍历它们时过滤这些边缘:

gremlin> g.V(1).
......1>   repeat(bothE().not(hasLabel('edge3')).otherV()).
......2>     times(4).
......3>     emit().
......4>   simplePath().
......5>   dedup()
==>v[2]
==>v[3]
==>v[4]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM