Skip to content

Commit e89a12d

Browse files
committed
Updated to new naming scheme for relations.
1 parent 136bcf9 commit e89a12d

File tree

1 file changed

+99
-89
lines changed

1 file changed

+99
-89
lines changed

cypher_query_timing.py

+99-89
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Copyright (C) 2013 ISI Foundation
66
# written by Ciro Cattuto <[email protected]>
7+
# and Andre' Panisson <[email protected]>
78
#
89
# This program is free software: you can redistribute it and/or modify
910
# it under the terms of the GNU General Public License as published by
@@ -35,12 +36,17 @@
3536
ret = gdb.query(q="""START run=node(%d) MATCH run-[:RUN_FRAME]->frame WHERE frame.frame_id = %d RETURN frame""" % (RUN_ID, 8084), returns=client.Node)[0]
3637
FRAME_ID = ret[0]._get_id()
3738

38-
ret = gdb.query(q="""START run=node(%d) MATCH run-[:RUN_TAG]->tag WHERE tag.tag = %d RETURN tag""" % (RUN_ID, 1138), returns=client.Node)[0]
39-
TAG_ID = ret[0]._get_id()
39+
ret = gdb.query(q="""START run=node(%d) MATCH run-[:RUN_ACTOR]->actor WHERE actor.actor = %d RETURN actor""" % (RUN_ID, 1138), returns=client.Node)[0]
40+
ACTOR_ID = ret[0]._get_id()
41+
ACTOR1_ID = ACTOR_ID
42+
43+
ret = gdb.query(q="""START run=node(%d) MATCH run-[:RUN_ACTOR]->actor WHERE actor.actor = %d RETURN actor""" % (RUN_ID, 1146), returns=client.Node)[0]
44+
ACTOR2_ID = ret[0]._get_id()
45+
46+
ret = gdb.query(q="""START run=node(%d) MATCH run-[:HAS_TIMELINE]->()-[y:NEXT_LEVEL]->()-[m:NEXT_LEVEL]->()-[d:NEXT_LEVEL]->()-[h:NEXT_LEVEL]->hour WHERE d.day = 29 and h.hour = 10
47+
RETURN hour""" % RUN_ID, returns=client.Node)[0]
48+
HOUR_ID = ret[0]._get_id()
4049

41-
TAG1_ID = TAG_ID
42-
ret = gdb.query(q="""START run=node(%d) MATCH run-[:RUN_TAG]->tag WHERE tag.tag = %d RETURN tag""" % (RUN_ID, 1146), returns=client.Node)[0]
43-
TAG2_ID = ret[0]._get_id()
4450

4551
# =========================================
4652

@@ -51,147 +57,150 @@
5157
RETURN frame ORDER BY frame.timestamp
5258
""" % RUN_NAME
5359

60+
5461
QUERY2 = """
5562
START frame = node(%d)
56-
MATCH frame-[:FRAME_TAG]-tag
57-
RETURN tag.name
63+
MATCH frame-[:FRAME_ACTOR]-actor
64+
RETURN actor.name
5865
""" % FRAME_ID
5966

67+
6068
QUERY3 = """
61-
START frame=node(%s)
62-
MATCH frame-[r:FRAME_EDGE]-edge
69+
START frame = node(%s)
70+
MATCH frame-[r:FRAME_INTERACTION]-interaction
6371
WHERE r.weight > %d
64-
RETURN edge.tag1, edge.tag2, r.weight;
72+
RETURN interaction.actor1, interaction.actor2, r.weight;
6573
""" % (FRAME_ID, 0)
6674

75+
6776
QUERY4 = """
6877
START run = node(%d)
69-
MATCH run-[:RUN_TAG]->tag<-[r:FRAME_TAG]-()
70-
RETURN tag.name, count(r)
78+
MATCH run-[:RUN_ACTOR]->actor<-[r:FRAME_ACTOR]-()
79+
RETURN actor.name, count(r)
7180
""" % RUN_ID
7281

82+
7383
QUERY5 = """
7484
START run = node(%d)
75-
MATCH run-[:RUN_TAG]->tag<-[r:FRAME_TAG]-()
76-
WITH tag.name as name, COUNT(r) as freq
85+
MATCH run-[:RUN_ACTOR]->actor<-[r:FRAME_ACTOR]-()
86+
WITH actor.name as name, COUNT(r) as freq
7787
WHERE freq > 1000
7888
RETURN name, freq ORDER BY freq DESC
7989
""" % RUN_ID
8090

91+
8192
QUERY5b = """
8293
START run = node(%d)
83-
MATCH run-[:RUN_TAG]-tag
84-
WITH tag
85-
MATCH ()-[r:FRAME_TAG]-tag
86-
WITH tag.name as name, COUNT(r) as freq
94+
MATCH run-[:RUN_ACTOR]-actor
95+
WITH actor
96+
MATCH ()-[r:FRAME_ACTOR]-actor
97+
WITH actor.name as name, COUNT(r) as freq
8798
WHERE freq > 1000
8899
RETURN name, freq ORDER BY freq DESC;
89100
""" % RUN_ID
90101

102+
91103
QUERY6 = """
92-
START tag = node(%d)
93-
MATCH ()-[d:NEXT_LEVEL]->()-[:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-()-[:FRAME_TAG]-tag
104+
START actor = node(%d)
105+
MATCH ()-[d:NEXT_LEVEL]->()-[:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-()-[:FRAME_ACTOR]-actor
94106
RETURN DISTINCT(d.day)
95-
""" % TAG_ID
107+
""" % ACTOR_ID
108+
96109

97110
QUERY6b = """
98-
START tag = node(%d)
99-
MATCH frame-[:FRAME_TAG]-tag
111+
START actor = node(%d)
112+
MATCH frame-[:FRAME_ACTOR]-actor
100113
RETURN DISTINCT(frame.day)
101-
""" % TAG_ID
114+
""" % ACTOR_ID
115+
102116

103117
QUERY7 = """
104-
START tag1 = node(%d)
105-
MATCH tag1<-[:EDGE_TAG]-()-[:EDGE_TAG]->tag2
106-
RETURN tag2.name ORDER BY tag2.name
107-
""" % TAG_ID
118+
START actor1 = node(%d)
119+
MATCH actor1<-[:INTERACTION_ACTOR]-()-[:INTERACTION_ACTOR]->actor2
120+
RETURN actor2.name ORDER BY actor2.name
121+
""" % ACTOR_ID
122+
108123

109124
QUERY8 = """
110-
START tag1 = node(%d)
111-
MATCH tag1<-[:EDGE_TAG]-edge-[:EDGE_TAG]->tag2
112-
WITH edge, tag2
113-
MATCH ()-[d:NEXT_LEVEL]->()-[:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-()-[:FRAME_EDGE]-edge
125+
START actor1 = node(%d)
126+
MATCH actor1<-[:INTERACTION_ACTOR]-interaction-[:INTERACTION_ACTOR]->actor2
127+
WITH interaction, actor2
128+
MATCH ()-[d:NEXT_LEVEL]->()-[:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-()-[:FRAME_INTERACTION]-interaction
114129
WHERE d.day = 7
115-
RETURN DISTINCT(tag2.name)
116-
""" % TAG_ID
130+
RETURN DISTINCT(actor2.name)
131+
""" % ACTOR_ID
132+
117133

118134
QUERY9 = """
119-
START tag1 = node(%d), tag2 = node(%d)
120-
MATCH tag1<-[:EDGE_TAG]-()-[:EDGE_TAG]->tag
121-
WITH COLLECT(tag) as neighs1, tag2
122-
MATCH tag2<-[:EDGE_TAG]-()-[:EDGE_TAG]->tag
123-
WHERE tag IN neighs1
124-
RETURN tag
125-
""" % (TAG1_ID, TAG2_ID)
135+
START actor1 = node(%d), actor2 = node(%d)
136+
MATCH actor1<-[:INTERACTION_ACTOR]-()-[:INTERACTION_ACTOR]->actor
137+
WITH COLLECT(actor) as neighs1, actor2
138+
MATCH actor2<-[:INTERACTION_ACTOR]-()-[:INTERACTION_ACTOR]->actor
139+
WHERE actor IN neighs1
140+
RETURN actor
141+
""" % (ACTOR1_ID, ACTOR2_ID)
142+
126143

127144
QUERY9b = """
128-
START tag1 = node(%d), tag2 = node(%d)
129-
MATCH tag1<-[:EDGE_TAG]-()-[:EDGE_TAG]->tag<-[:EDGE_TAG]-()-[:EDGE_TAG]->tag2
130-
RETURN tag
131-
""" % (TAG1_ID, TAG2_ID)
145+
START actor1 = node(%d), actor2 = node(%d)
146+
MATCH actor1<-[:INTERACTION_ACTOR]-()-[:INTERACTION_ACTOR]->actor<-[:INTERACTION_ACTOR]-()-[:INTERACTION_ACTOR]->actor2
147+
RETURN actor
148+
""" % (ACTOR1_ID, ACTOR2_ID)
149+
132150

133151
QUERY10 = """
134152
START run = node(%d)
135-
MATCH run-[:RUN_TAG]-tag-[r:EDGE_TAG]-()
136-
RETURN tag.name, COUNT(r) ORDER BY COUNT(r) DESC
153+
MATCH run-[:RUN_ACTOR]-actor-[r:INTERACTION_ACTOR]-()
154+
RETURN actor.name, COUNT(r) ORDER BY COUNT(r) DESC
137155
""" % RUN_ID
138156

139-
# get the tag focused network during the day 29, hour 10
140157

141158
QUERY11a = """
142-
START tag = node(%d)
143-
MATCH neigh1<-[:EDGE_TAG]-edge1-[:EDGE_TAG]->tag,
144-
()-[d1:NEXT_LEVEL]->()-[h1:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_EDGE]-edge1
159+
START actor = node(%d)
160+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction1-[:INTERACTION_ACTOR]->actor,
161+
()-[d1:NEXT_LEVEL]->()-[h1:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_INTERACTION]-interaction1
145162
WHERE d1.day = 29 and h1.hour = 10
146-
WITH distinct neigh1, tag
147-
MATCH neigh2<-[:EDGE_TAG]-edge2-[:EDGE_TAG]->tag,
148-
()-[d2:NEXT_LEVEL]->()-[h2:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_EDGE]-edge2
163+
WITH DISTINCT neigh1, actor
164+
MATCH neigh2<-[:INTERACTION_ACTOR]-interaction2-[:INTERACTION_ACTOR]->actor,
165+
()-[d2:NEXT_LEVEL]->()-[h2:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_INTERACTION]-interaction2
149166
WHERE d2.day = 29 and h2.hour = 10
150167
WITH distinct neigh2, neigh1
151-
MATCH neigh1<-[:EDGE_TAG]-edge3-[:EDGE_TAG]->neigh2,
152-
()-[d3:NEXT_LEVEL]->()-[h3:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_EDGE]-edge3
168+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction3-[:INTERACTION_ACTOR]->neigh2,
169+
()-[d3:NEXT_LEVEL]->()-[h3:NEXT_LEVEL]->()-[:TIMELINE_INSTANCE]-frame-[:FRAME_INTERACTION]-interaction3
153170
WHERE d3.day = 29 and h3.hour = 10
154-
RETURN distinct neigh1.tag, neigh2.tag ORDER BY neigh1.tag, neigh2.tag;
155-
""" % TAG_ID
171+
RETURN DISTINCT neigh1.actor, neigh2.actor ORDER BY neigh1.actor, neigh2.actor;
172+
""" % ACTOR_ID
156173

157-
ret = gdb.query(q="""
158-
START run = node(%d)
159-
MATCH run-[:HAS_TIMELINE]->()-[y:NEXT_LEVEL]->()-[m:NEXT_LEVEL]->()-[d:NEXT_LEVEL]->()-[h:NEXT_LEVEL]->hour
160-
WHERE d.day = 29 and h.hour = 10
161-
RETURN hour
162-
""" % RUN_ID, returns=client.Node)[0]
163-
HOUR_ID = ret[0]._get_id()
164174

165175
QUERY11b = """
166-
START tag = node(%d), hour = node(%d)
167-
MATCH neigh1<-[:EDGE_TAG]-edge1-[:EDGE_TAG]->tag,
168-
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_EDGE]->edge1
169-
WITH distinct hour, neigh1, tag
170-
MATCH neigh2<-[:EDGE_TAG]-edge2-[:EDGE_TAG]->tag,
171-
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_EDGE]->edge2
172-
WITH distinct hour, neigh1, neigh2
173-
MATCH neigh1<-[:EDGE_TAG]-edge3-[:EDGE_TAG]->neigh2,
174-
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_EDGE]->edge3
175-
RETURN distinct neigh1.tag, neigh2.tag ORDER BY neigh1.tag, neigh2.tag;
176-
""" % (TAG_ID, HOUR_ID)
176+
START actor = node(%d), hour = node(%d)
177+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction1-[:INTERACTION_ACTOR]->actor,
178+
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_INTERACTION]->interaction1
179+
WITH DISTINCT hour, neigh1, actor
180+
MATCH neigh2<-[:INTERACTION_ACTOR]-interaction2-[:INTERACTION_ACTOR]->actor,
181+
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_INTERACTION]->interaction2
182+
WITH DISTINCT hour, neigh1, neigh2
183+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction3-[:INTERACTION_ACTOR]->neigh2,
184+
hour-[:TIMELINE_INSTANCE]->frame-[:FRAME_INTERACTION]->interaction3
185+
RETURN DISTINCT neigh1.actor, neigh2.actor ORDER BY neigh1.actor, neigh2.actor;
186+
""" % (ACTOR_ID, HOUR_ID)
187+
177188

178189
QUERY11c = """
179-
START tag = node(%d)
180-
MATCH neigh1<-[:EDGE_TAG]-edge1-[:EDGE_TAG]->tag,
181-
frame1-[:FRAME_EDGE]->edge1
190+
START actor = node(%d)
191+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction1-[:INTERACTION_ACTOR]->actor,
192+
frame1-[:FRAME_INTERACTION]->interaction1
182193
WHERE frame1.day = 29 and frame1.hour = 10
183-
WITH distinct neigh1, tag
184-
MATCH neigh2<-[:EDGE_TAG]-edge2-[:EDGE_TAG]->tag,
185-
frame2-[:FRAME_EDGE]->edge2
194+
WITH DISTINCT neigh1, actor
195+
MATCH neigh2<-[:INTERACTION_ACTOR]-interaction2-[:INTERACTION_ACTOR]->actor,
196+
frame2-[:FRAME_INTERACTION]->interaction2
186197
WHERE frame2.day = 29 and frame2.hour = 10
187-
WITH distinct neigh1, neigh2
188-
MATCH neigh1<-[:EDGE_TAG]-edge3-[:EDGE_TAG]->neigh2,
189-
frame3-[:FRAME_EDGE]->edge3
198+
WITH DISTINCT neigh1, neigh2
199+
MATCH neigh1<-[:INTERACTION_ACTOR]-interaction3-[:INTERACTION_ACTOR]->neigh2,
200+
frame3-[:FRAME_INTERACTION]->interaction3
190201
WHERE frame3.day = 29 and frame3.hour = 10
191-
RETURN distinct neigh1.tag, neigh2.tag ORDER BY neigh1.tag, neigh2.tag;
192-
193-
""" % TAG_ID
194-
202+
RETURN DISTINCT neigh1.actor, neigh2.actor ORDER BY neigh1.actor, neigh2.actor;
203+
""" % ACTOR_ID
195204

196205

197206

@@ -202,6 +211,7 @@
202211
('QUERY10', QUERY10),
203212
('QUERY11a', QUERY11a), ('QUERY11b', QUERY11b), ('QUERY11c', QUERY11c) ]
204213

214+
205215
# =========================================
206216

207217
def time_query(gdb, query, N=10):

0 commit comments

Comments
 (0)