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?
source share