问题
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