-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathneo4j_commands.java
executable file
·124 lines (117 loc) · 4.88 KB
/
neo4j_commands.java
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
124
---------------------------------------------
---------------Find All Nodes--------------
MATCH (n)
RETURN n
---------------------------------------------
-----Find All Relations---------
MATCH p=()-[r:LOCATED_AT]->() RETURN p LIMIT 100
---------------------------------------------
------Find Shortest Path Between Nodes--------
match(s:Stop), (e:Stop)
where s.name starts with "U Schlump" and e.name starts with "Sartoriusstraße"
match p = shortestpath((s)-[*]-(e))
return p
-------------------------------------------------
------Find Indirect Path Between Nodes-----------
MATCH(s:Stop), (e:Stop)
WHERE s.name starts with "U Schlump" and e.name = "U Eppendorfer Baum"
match p = allshortestpaths((s)-[*]-(e))
where NONE (x in relationships(p) where type(x)="OPERATES")
return p
limit 25
-------------------------------------------------------
------Find Specific Indirect Path Between Nodes--------
MATCH (tu:Stop {name:"U Schlump"})--(st_tu:Stoptime),
(ar:Stop {name:"Sartoriusstraße"})--(st_ar:Stoptime),
p1=((st_tu)-[:PRECEDES*]->(st_midway_arr:Stoptime)),
(st_midway_arr)--(midway:Stop),
(midway)--(st_midway_dep:Stoptime),
p2=((st_midway_dep)-[:PRECEDES*]->(st_ar))
WHERE
st_tu.departure_time > "08:00:00"
AND st_tu.departure_time < "11:00:00"
AND st_midway_arr.arrival_time > st_tu.departure_time
AND st_midway_dep.departure_time > st_midway_arr.arrival_time
AND st_ar.arrival_time > st_midway_dep.departure_time
RETURN
tu,st_tu,ar,st_ar,p1,p2,midway
order by (st_ar.arrival_time_int-st_tu.departure_time_int) ASC
limit 1
-------------------------------------------------------
------Find Specific Indirect Path Between Nodes--------
match(n:Route),(s:Stop),(e:Stop)
where n.short_name='U3' and s.name starts with "U Schlump" and e.name starts with "U Eppendorfer Baum"
match p = shortestpath((s)-[*]-(e))
return p
limit 25
-------------------------------------------------------
------Change Datatype Of A Node--------
match(a:Agency)
where a.id=toInt(a.id)
with a
set a.id = toString(a.id)
return count(a)
-------------------------------------------------------
------Direct Route--------
match (tu:Stop {name: "U Schlump"})--(tu_st:Stoptime)
where tu_st.departure_time > "20:00:00"
AND tu_st.departure_time < "22:00:00"
with tu, tu_st
match (ant:Stop {name:"Sartoriusstraße"})--(ant_st:Stoptime)
where ant_st.arrival_time < "22:00:00"
AND ant_st.arrival_time > "20:00:00"
and ant_st.arrival_time > tu_st.departure_time
with ant,ant_st,tu, tu_st
match p = allshortestpaths((tu_st)-[*]->(ant_st))
with nodes(p) as n
unwind n as nodes
match (nodes)-[r]-()
return nodes,r
------------------------Route With Midway Station---------------------------------
MATCH (tu:Stop {name:"U Schlump"})--(st_tu:Stoptime),
(ar:Stop {name:"Sartoriusstraße"})--(st_ar:Stoptime),
p1=((st_tu)-[:PRECEDES*]->(st_midway_arr:Stoptime)),
(st_midway_arr)--(midway:Stop),
(midway)--(st_midway_dep:Stoptime),
p2=((st_midway_dep)-[:PRECEDES*]->(st_ar))
WHERE
st_tu.departure_time > "21:00:00"
AND st_tu.departure_time < "22:00:00"
AND st_midway_arr.arrival_time > st_tu.departure_time
AND st_midway_dep.departure_time > st_midway_arr.arrival_time
AND st_ar.arrival_time > st_midway_dep.departure_time
RETURN
tu,st_tu,ar,st_ar,p1,p2,midway
order by (st_ar.arrival_time_int-st_tu.departure_time_int) ASC
limit 1
---------------------Assigning Relationship Between Stops------------------------------------
match (s1:Stoptime)-[:PART_OF_TRIP]->(t:Trip),
(s2:Stoptime)-[:PART_OF_TRIP]->(t)
where s2.stop_sequence=s1.stop_sequence+1
and not (s1)-[:PRECEDES]->(s2)
create (s1)-[:PRECEDES]->(s2);
----------------------Shortest Path Between Stations-----------------------------------
MATCH (s:Stop {name:"U Schlump"})--(sTime:Stoptime),
(e:Stop {name:"Sartoriusstraße"})--(eTime:Stoptime)
where sTime.departure_time > "20:00:00" AND sTime.departure_time < "22:00:00" and eTime.arrival_time < "22:00:00"
AND eTime.arrival_time > "20:00:00"
match path = allshortestpaths((sTime)-[*]-(eTime))
return length(path), path
---------------------Weights Calculation--------------------
match (tu:Stop {name: "U Schlump"})--(tu_st:Stoptime)
where tu_st.departure_time > "20:00:00"
AND tu_st.departure_time < "22:00:00"
with tu, tu_st
match (ant:Stop {name:"Sartoriusstraße"})--(ant_st:Stoptime)
where ant_st.arrival_time < "22:00:00"
AND ant_st.arrival_time > "20:00:00"
and ant_st.arrival_time > tu_st.departure_time
with ant,ant_st,tu, tu_st
match p = allshortestpaths((tu_st)-[r:PRECEDES*]->(ant_st))
return p, reduce(EstimatedTime=0, r in relationships(p) | EstimatedTime+(r.weight)+2) AS TotalWeight
limit 10
--------------------Specific Relationships---------------
MATCH(s:Stop), (e:Stop)
WHERE s.name = 'U Schlump' AND e.name = 'Sartoriusstraße'
MATCH p = allshortestpaths((s)-[*]-(e))
WHERE ALL (r IN relationships(p) WHERE type(r) = 'PART_OF_TRIP' OR type(r) = 'LOCATED_AT')