Transform gremlin to cyper query

Hi All,
I am very new in cypher language, can someone help me to translate the following gremlin queries to cypher query.

  1. g.V('v1').outE().valueMap().count() //Count all the out going path from given vertex.
  2. g.V('v2').repeat(out()).times(2).count() // Count 2 hops paths from given vertex.
  3. g.V().has("value", "abc").path(). //Print all the paths from given vertex.
  4. g.V().has("value", "xyz").path().by("value") //Print all the paths from given vertex along with vertex attributes value.
  5. g.V().has("value", "klm").inE().outV().path() //Print all the paths of out going vertices of all the incoming vertices of a given vertex
  6. g.V().has("value", "pqr").outE().inV().path() //Print all the paths of incoming vertices of all the out going vertices of a given vertex.
    7.g.V().has('CID','value','lmn').values() //Print all the attributes of a given vertex in label CID.

Regards,

What have you tried so far?

1 Like

Don't get me wrong. The community here is very helpful. However "please do my job" style questions are not really appreciated.

Therefore get started with Cypher maybe via the free online course https://neo4j.com/graphacademy/online-training/introduction-to-neo4j-40/, apply what you've learned and come back with specific questions.

If you want "do my job" style, I'm happy to bring you in touch with our sales reps for some paying consulting package.

1 Like

@steak.armbruster your answer was ok until it wasn't anymore: from the moment you mentioned the sales and paid support.
I like to think of this community as an graph enthusiast community, which means both free and "for free", where people look for support, and which was actually built around the enormous support done "for free" by Michael Hunger and the likes.
This type of question is the perfect example of a question which Michael would have helped with. We have to blame him for being too kind and helpful and thus getting us used to being cocooned and always have answers to our questions.
If someone already had paid support, he wouldn't be asking here in the first place. Also, if someone wanted paid support, he, again, wouldn't be asking here.
Let's just say that lot of knowledge from paid support, which people may be looking for, does not appear here, even as hints to solve various issues. So, paid support stays for big projects, but for short "fire and forget" questions we should manage.
I personally feel that your reply is from a position of force so maybe you can rephrase your attitude. That is, if you want this community to ever grow @karin.wolok

Hello Ramdabam,
For the following, we will be using console.neo4j.org on the default graph so please paste and run the queries on the botton textbox.
Generically, in Cypher terms:

  • 1 a vertex (https://en.wikipedia.org/wiki/Vertex_(graph_theory)) is a node so for outE(), in Cypher you can count all outgoing relationships (edges in Gremlin) (and also incoming) by specifying the direction of the relationship by using ">" (or "<"). It will become more obvious where to use the ">" in the following examples.
    "match (n:Crew{name:'Neo'})-[r]->() return n, count(r)"
    • "match" is the instruction to parse the graph
    • "(n:Crew{name:'Neo'})" is the starting node searched by label "Crew" and by property called "name" with value "Neo"
    • -[r]->* is the outgoing relationship. notice the direction: ">" for outgoing and "<-[r]-" for incoming
    • () means any node, as means any relationship
  • 2 repeat does not exist but you can instruct cypher to walk past a variable number of relationships https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength
    "match (n:Crew{name:'Neo'})-[r:KNOWS2..2]-(m) return n as n,r,m"
    Notice the 2..2, where "
    " gives the instruction for a variable length, first 2 is a minimum of path length and second 2 is the maximum length of path
  • 3 all paths from current node is just letting the path length be free :)) and for "has("value", "abc")" you either use "{name:'Neo'}" or the "where" clause for match https://neo4j.com/docs/cypher-manual/current/clauses/where/ , so "match (n:Crew{name:'Neo'})-[r:KNOWS*..]-(m) return n as n,r,m"
  • 4 all vertex attribute values: well, you can name your path and return everything in it: "match path=(n:Crew{name:'Neo'})-[r:KNOWS*0..]-(m) return n,r,m, path"
  • 4 displaying a property of all nodes in path a little more tricky, as a traversal in Gremlin is not how things work in Cypher: whereas in Gremnlin you wall a path, in Cyher you get the path, so you need to iterate the path afterwards "match path=(n:Crew{name:'Neo'})-[r:KNOWS*0..]-(m) with nodes(path) as noduri unwind noduri as nod return nod.name"
  • 5 notice the direction of the relationship as "<" into node n. by using it means you don't care about the relationships and also don't name them as you don't need to return name. but, the following query does this: for all nodes, first match the incoming nodes and then bring the outgoing nodes of those "match (n)<--(m)-->(p) return n,m,p"
  • 6 is the vice-versa of 5 - do notice the location of "<" and ">" : "match (n)-->(m)<--(p) return n,m,p"
  • 7 well, as said above, for label we use ":label" and for attributes, just the .property . So it's the first query, "match (n:Crew{name:'Trinity'}) return n" where "Crew" is the label and "Trinity" is the value of attribute "name"