-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode_labels_and_their_relationships.cypher
29 lines (28 loc) · 1.24 KB
/
Node_labels_and_their_relationships.cypher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// List node labels and their relationship types, their count and their density.
MATCH (nodeByLabel)
WITH labels(nodeByLabel) AS nodeLabels
,collect(nodeByLabel) AS nodesWithThatLabels
,count(nodeByLabel) AS numberOfNodesWithThatLabels
UNWIND nodesWithThatLabels AS nodeWithThatLabels
MATCH (nodeWithThatLabels)-[relation]->(target)
WITH nodeLabels AS sourceLabels
,numberOfNodesWithThatLabels AS numberOfNodesWithSameLabelsAsSource
,type(relation) AS relationType
,labels(target) AS targetLabels
,count(DISTINCT relation) AS numberOfRelationships
WITH sourceLabels
,relationType
,targetLabels
,numberOfRelationships
,numberOfNodesWithSameLabelsAsSource
,count{ MATCH (targetWithLabel) WHERE labels(targetWithLabel) = targetLabels } AS numberOfNodesWithSameLabelsAsTarget
RETURN sourceLabels
,relationType
,targetLabels
,numberOfRelationships
,numberOfNodesWithSameLabelsAsSource
,numberOfNodesWithSameLabelsAsTarget
,toFloat(numberOfRelationships)
/ ( numberOfNodesWithSameLabelsAsSource * numberOfNodesWithSameLabelsAsTarget)
* 100 AS densityInPercent
ORDER BY numberOfRelationships DESC