我怎么能在janusgraph中使用?

时间:2017-12-06 06:06:31

标签: gremlin tinkerpop3 janusgraph

gremlin> a = graph.addVertex("name", "alice")
gremlin> b = graph.addVertex("name", "bobby")
gremlin> c = graph.addVertex("name", "cindy")
gremlin> d = graph.addVertex("name", "david")
gremlin> e = graph.addVertex("name", "eliza")
gremlin> a.addEdge("rates",b,"tag","ruby","value",9)
gremlin> b.addEdge("rates",c,"tag","ruby","value",8)
gremlin> c.addEdge("rates",d,"tag","ruby","value",7)
gremlin> d.addEdge("rates",e,"tag","ruby","value",6)
gremlin> e.addEdge("rates",a,"tag","java","value",9)

g.V().has('name', 'alice').repeat(out()).times(6).cyclicPath().path().by('name')

我想以alice节点结束。我想重复所有不希望将时间指定为6的步骤。要求是我想从alice获取所有循环或从图中获取所有循环。

1 个答案:

答案 0 :(得分:3)

您可以参考TinkerPop食谱中的Cycle Detection部分 - 它可以很容易地适应您的示例图表:

gremlin> g.V().has('name', 'alice').as('a').
......1>   repeat(out().simplePath()).
......2>     emit(loops().is(gt(1))).
......3>   both().where(eq('a')).
......4>   path().
......5>     by('name').
......6>   dedup().
......7>     by(unfold().order().dedup().fold())
==>[alice,bobby,cindy,david,eliza,alice]