forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbi-21.cypher
63 lines (63 loc) · 1.5 KB
/
bi-21.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
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
// Q21. Zombies in a country
/*
:param {
country: 'Ethiopia',
endDate: 20130101000000000
}
*/
MATCH (country:Country {name: $country})
WITH
country,
$endDate/10000000000000 AS endDateYear,
$endDate/100000000000%100 AS endDateMonth
MATCH
(country)<-[:IS_PART_OF]-(:City)<-[:IS_LOCATED_IN]-(zombie:Person)
OPTIONAL MATCH
(zombie)<-[:HAS_CREATOR]-(message:Message)
WHERE zombie.creationDate < $endDate
AND message.creationDate < $endDate
WITH
country,
zombie,
endDateYear,
endDateMonth,
zombie.creationDate/10000000000000 AS zombieCreationYear,
zombie.creationDate/100000000000%100 AS zombieCreationMonth,
count(message) AS messageCount
WITH
country,
zombie,
12 * (endDateYear - zombieCreationYear )
+ (endDateMonth - zombieCreationMonth)
+ 1 AS months,
messageCount
WHERE messageCount / months < 1
WITH
country,
collect(zombie) AS zombies
UNWIND zombies AS zombie
OPTIONAL MATCH
(zombie)<-[:HAS_CREATOR]-(message:Message)<-[:LIKES]-(likerZombie:Person)
WHERE likerZombie IN zombies
WITH
zombie,
count(likerZombie) AS zombieLikeCount
OPTIONAL MATCH
(zombie)<-[:HAS_CREATOR]-(message:Message)<-[:LIKES]-(likerPerson:Person)
WHERE likerPerson.creationDate < $endDate
WITH
zombie,
zombieLikeCount,
count(likerPerson) AS totalLikeCount
RETURN
zombie.id,
zombieLikeCount,
totalLikeCount,
CASE totalLikeCount
WHEN 0 THEN 0.0
ELSE zombieLikeCount / toFloat(totalLikeCount)
END AS zombieScore
ORDER BY
zombieScore DESC,
zombie.id ASC
LIMIT 100