-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgraph_denhaag.cql
124 lines (98 loc) · 3.3 KB
/
graph_denhaag.cql
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//cypher query language
//Graph analytics Den Haag crime project
//03212026
//Pedro V
///////////////Defining the Graph///////////////
//Loading table
LOAD CSV WITH HEADERS FROM "file:///home/pedrohserrano/den_haag_full.csv" AS table
//Defining vertex
MERGE (o:Zone {
Name: table.obu_naam,
Offenders: toInt(table.ooffenders0),
Crime: toInt(table.Crim_o)})
MERGE (d:Zone {
Name: table.dbu_naam,
Offenders: toInt(table.doffenders0),
Crime: toInt(table.Crim_d)})
MERGE (r:Reg {Name: table.owk_name})
MERGE (y:Year {Name: toInt(table.year)})
//Defining edges
MERGE (o)-[:Move_to {dist: toInt(table.migra0)}]->(d)
MERGE (o)-[:Belong]->(r)
MERGE (r)-[:Crime {Orig: toInt(table.Crim_o), Dest: toInt(table.Crim_d)}]-(y)
//https://github.com/pedrohserrano/graph-thehague/blob/master/den_haag_sample.csv
///////////////Graph decriptive analysis///////////////
//Count vertex total
MATCH (n)
RETURN count(n)
//Count edges total
MATCH ()-[r]->()
RETURN count(r)
//Outdegrees vertex type: Zone
MATCH (n:Zone)-[r:Move_to]->()
RETURN n.Name as Node, count(r) as Outdegree
ORDER BY Outdegree DESC
UNION
MATCH (a:Zone)-[r:Move_to]->(leaf)
WHERE not((leaf)-->())
RETURN leaf.Name as Node, 0 as Outdegree
//On the document it shows rank top 5 and last 5
//Indegrees vertex type: Zone
MATCH (n:Zone)<-[r:Move_to]-()
RETURN n.Name as Node, count(r) as Indegree
ORDER BY Indegree DESC
UNION
MATCH (a:Zone)<-[r:Move_to]-(root)
WHERE not((root)<--())
RETURN root.Name as Node, 0 as Indegree
//On the document it shows rank top 5 and last 5
//Total degrees vertex type: Zone
MATCH (n:Zone)-[r:Move_to]-()
RETURN n.Name, count(distinct r) as Degree
ORDER BY Degree DESC
//Graphs degree Histogram
MATCH (n:Zone)-[r:Move_to]-()
WITH n as Nodes, count(distinct r) as Degree
RETURN Degree, Count(Nodes)
ORDER BY Degree ASC
//Calculate the diameter of the subgraph in which only considers colonies
MATCH (z1:Zone),(z2:Zone)
WHERE z1 <> z2
WITH z1, z2
MATCH p=shortestPath((z1)-[r:Move_to*]->(z2))
RETURN z1.Name, z2.Name, length(p)
ORDER BY length(p) DESC LIMIT 1
//Since we have the the diameter then all shortest paths
MATCH p = allShortestPaths((n:Zone)-[r:Move_to*]-(m:Zone))
WHERE n.Name='Archipelbuurt' AND m.Name = 'Transvaalkwartier-Midden'
RETURN EXTRACT(n IN NODES(p)| n.Name) AS Paths
///////////////Análisis exploratorio del grafo///////////////
//Show up all relations
MATCH (o)-[:Belong]->(r)-[c:Crime]->(y) RETURN o,r,y
//Image 1 in the document
//Show up all edges which have move_to relation ordered
MATCH (n:Zone)-[:Move_to*]->(m:Zone)
RETURN n, m
ORDER BY n.Crime DESC, n.Offenders DESC
LIMIT 10
//En el documento se muestran los 5 distintos
//Show up top 10 people movement
MATCH (n:Zone)-[r:Move_to]->(m:Zone)
WHERE n<>m
RETURN n.Name, r
ORDER BY r.dist DESC, n.Crime DESC, n.Offenders DESC
LIMIT 10
//En el documento va la gráfica y el grafo, ya
//Show up the relation zone belong to region, then to see communities
MATCH (n:Zone)-[r:Belong]->(m:Reg)
WHERE n<>m
RETURN n, m, r
ORDER BY n.Crime DESC
LIMIT 100
//Is the second graph on the document
//Dijkstras algorithm to the most influential zone
MATCH (n:Zone {Name:'Kerketuinen/Zichtenburg'}), (m:Zone),
path = shortestPath((n:Zone)-[:Move_to*]->(m:Zone))
WITH REDUCE(dist = 0, rel in rels(path) | dist + toInt(rel.dist)) AS distance, path, n, m
RETURN n, m, path, distance
ORDER BY distance desc