按边缘标签过滤 Gremlin 遍历

Filtering a Gremlin Traversal by edge label

我正在尝试使用 Gremlin 从起始节点向外遍历到 X 连接度内的所有连接节点。连接的方向无关紧要,所以我使用 both() 函数。我还希望能够防止遍历跨越具有特定标签的边缘。这是一个示例图表。

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()

到目前为止我的遍历是这样的:

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

然而,这并不是我想要的。我想要一些东西,如果它必须穿过指定的边缘,它实际上会阻止遍历器击中顶点。我当前的实现过滤具有传入边的顶点,但在某些情况下,如果遍历器穿过不同的边到达那里,我可能仍希望该顶点出现在结果中。

这有意义吗?简而言之,我试图专门针对边进行过滤,而不是根据顶点与其边的关系进行过滤。

我想我听懂了你说的,你不能只使用 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]