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?
Asked
Active
Viewed 271 times
2
-
What exactly do you mean by "cycle"? A vertex with an edge pointing to itself? A simple triangle? Or an arbitrary length path that starts and ends at the same vertex? – Daniel Kuppitz Apr 23 '15 at 09:37
-
The last one, I give a vertex and function return a path which start and ends at the same vertex. – user3762819 Apr 23 '15 at 10:39
1 Answers
4
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]]

Daniel Kuppitz
- 10,846
- 1
- 25
- 34