Cycles in Gremlin/Cypher

99封情书 提交于 2019-12-24 04:07:09

问题


I'm making a presentation about how some elements looks in Neo4j's Cypher and Titan's Gremlin i.e. add new vertex, look for relation etc. I have a problem with looking for cyclec. Is there any function in these 2 languages which can return a cycles i.e. for given vertex?


回答1:


Here's how you do it in Gremlin:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.v(2).addEdge("knows", g.v(6))
==>e[0][2-knows->6]
gremlin> g.v(6).addEdge("knows", g.v(1))
==>e[1][6-knows->1]
gremlin> v = g.v(1); v.as("v").out().dedup().loop("v") {true} {it.object == v}.path()
==>[v[1], v[2], v[6], v[1]]
gremlin> v.as("v").outE().dedup().inV().loop("v") {true} {it.object == v}.path()
==>[v[1], e[7][1-knows->2], v[2], e[0][2-knows->6], v[6], e[1][6-knows->1], v[1]]


来源:https://stackoverflow.com/questions/29808253/cycles-in-gremlin-cypher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!