-
Notifications
You must be signed in to change notification settings - Fork 1
/
neo4j
108 lines (89 loc) · 4.53 KB
/
neo4j
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
CREATE
(m:Person:Shinobi {name:'Madara', age:30}),
(s:Person:Kunoichi {name:'Sakura', age:20}),
(j:Person:Shinobi {name:'Jiraiya', age:60}),
(i:Person:Shinobi {name:'Itachi', age:30}),
(t:Person:Kunoichi {name:'Tsunade', age:60}),
(o:Person:Shinobi {name:'Orochimaru', age:50}),
(kon:City {name:'Konoha'}),
(sun:City {name:'Suna'}),
(m)-[:FRIEND_OF]->(s),
(m)-[:FRIEND_OF]->(t),
(m)-[:FRIEND_OF]->(i),
(m)-[:FRIEND_OF]->(j),
(s)-[:FRIEND_OF]->(j),
(o)-[:FRIEND_OF]->(j),
(s)-[:LIVE_IN]->(kon),
(j)-[:LIVE_IN]->(kon),
(m)-[:LIVE_IN]->(kon),
(t)-[:LIVE_IN]->(sun);
//The above block serves to create people, city, relationships and etc ... Everything in the Naruto universe hehehe (The above data does not match the truth)
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
RETURN me, potentialFriend, COUNT(*) AS mutualFriends
//Here I meet potential friends or friends of some friends In case should return Jiraiya, Tsunade and Sakura This being based on my only friend Madara ... Sakura besides being friends with Madara is also friends with Jiraiya who is Madara's friend.
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
WITH me, potentialFriend, COUNT(*) AS mutualFriends
RETURN me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace
//Here I meet potential friends and also research how many or which of them live in the same But I did not say where Itachi lived so he will never match ... he will bring the friends in common but he will not match in Persons of the same place.
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
WITH me, potentialFriend, COUNT(*) AS mutualFriends
RETURN me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace,
LABELS(me) = LABELS(potentialFriend) AS genre
//In this query I take all potential friends, plus everyone who lives in the same place and check if they are of the same sex as me, in case the only one that will return true is the Jiraiya who is also a man!(From here I recommend using the text mode of neo4j)
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
WITH me, potentialFriend, COUNT(*) AS mutualFriends
RETURN me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace,
abs( me.age - potentialFriend.age) AS differenceAge,
LABELS(me) = LABELS(potentialFriend) AS genre,
mutualFriends
//In this research above, I draw possible friends, Persons living in the same place, Persons of the same genre and the difference of acts between us and the possible friends
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
WITH me, potentialFriend, COUNT(*) AS mutualFriends
WITH me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace,
abs( me.age - potentialFriend.age) AS differenceAge,
LABELS(me) = LABELS(potentialFriend) AS genre,
mutualFriends
WHERE NOT (me)-[:FRIEND_OF]-(potentialFriend)
RETURN me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace,
abs( me.age - potentialFriend.age) AS differenceAge,
LABELS(me) = LABELS(potentialFriend) AS genre,
mutualFriends
//Here I delete who already is my friend in case that other crazy that I deleted (useless, but for who needs ...)
MATCH (me:Person {name: "Itachi"})
MATCH (me)-[:FRIEND_OF]-()-[:FRIEND_OF]-(potentialFriend)
WITH me, potentialFriend, COUNT(*) AS mutualFriends
WITH me,
potentialFriend,
SIZE((potentialFriend)-[:LIVE_IN]->()<-[:LIVE_IN]-(me)) AS samePlace,
abs( me.age - potentialFriend.age) AS differenceAge,
LABELS(me) = LABELS(potentialFriend) AS genre,
mutualFriends
WHERE NOT (me)-[:FRIEND_OF]-(potentialFriend)
WITH potentialFriend,
// 100 -> maxScore, 10 -> eightyPercentLevel, mutualFriends -> score (from the formula copied)
100 * (1 - exp((-1.0 * (log(5.0) / 10)) * mutualFriends)) AS mutualFriends,
samePlace * 10 AS samePlace,
-1 * (10 * (1 - exp((-1.0 * (log(5.0) / 20)) * differenceAge))) AS differenceAge,
CASE WHEN genre THEN 10 ELSE 0 END as sameType
RETURN potentialFriend,
{mutualFriends: mutualFriends,
samePlace: samePlace,
differenceAge:differenceAge,
sameType: sameType} AS parts,
mutualFriends + samePlace + differenceAge + sameType AS score
ORDER BY score DESC