Neo4j / Cypher - how can I get all trigger tricks?

With the introduction of labels, neo4j received neat mechanisms for managing objects. Now let's assume for a moment that we have a common graph with many different objects and would like to know which entities (labels) are related to each other. Here's the starting point: http://console-test.neo4j.org/?id=wdnbuj

Graph Setup: CYPHER 2.0 create (_1:Crew {name:"Neo"}), (_2:Crew {name:"Morpheus"}), (_3:Crew {name:"Trinity"}), (_4:Language {name:"Cypher"}), (_5:Machines {name:"Agent Smith"}), (_6:Machines {name:"The Architect"}), _1-[:KNOWS]->_2, _1-[:LOVES]->_3, _2-[:KNOWS]->_3, _2-[:KNOWS]->_4, _4-[:KNOWS]->_5, _5-[:CODED_BY]->_6 Query: CYPHER 2.0 match x-[r]->y return head(labels(x)) as head, type(r), head(labels(y)) as tail 

This will give us an overview of the objects that are related to each other:

 +--------------------------------------+ | head | type(r) | tail | +--------------------------------------+ | "Machines" | "CODED_BY" | "Machines" | | "Language" | "KNOWS" | "Machines" | | "Crew" | "KNOWS" | "Crew" | | "Crew" | "KNOWS" | "Language" | | "Crew" | "KNOWS" | "Crew" | | "Crew" | "LOVES" | "Crew" | +--------------------------------------+ 

Now. Is there a Cypher query that would return us different values ​​for these triples?

Bonus question: can we get their number / frequency?

+4
source share
1 answer

I just used your original request, adding clarity and quantity. Is this what you were looking for? Or do you want me to rip out the labels from the label collection (which is not easy without any unwind function).

 match x-[r]->y return distinct head(labels(x)) as head, type(r), head(labels(y)) as tail match x-[r]->y return head(labels(x)) as head, type(r), head(labels(y)) as tail, count(*) 
+2
source

Source: https://habr.com/ru/post/1481346/


All Articles