-
Notifications
You must be signed in to change notification settings - Fork 0
/
recommender.cypher
29 lines (24 loc) · 1.07 KB
/
recommender.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
// get average review overall (for heuristic)
MATCH (:Reviewer)-[:writeReview]->(r:Review)
RETURN AVG(toFloat(r.overall))
// list users and their apps (to find target)
MATCH (u:Reviewer)-[:writeReview]->(:Review)-[:review]->(a:App)
RETURN u.id AS user, u.name AS name, COLLECT(a.name) AS apps
// get recommendations (sorted by score)
MATCH (t:Reviewer {id : "A1U9Z3WD1PWQ09"})-[:writeReview]->(:Review)-[:review]->(a1:App),
(a1:App)-[:hasCategory]->(cat:Category)<-[:hasCategory]-(a2:App)
// find apps that other users have reviewed
OPTIONAL MATCH
(f:Reviewer)-[:writeReview]->(:Review)-[:review]->(a1:App),
(f:Reviewer)-[:writeReview]->(rev:Review)-[:review]->(a2:App)
// find related apps
OPTIONAL MATCH
(a1:App)-[rel:related]-(a2:App)
// avoid trivial case
WHERE a1 <> a2
// compute scores by components
WITH a2.name AS target, toFloat(a2.rating) AS ratScore,
COUNT(DISTINCT cat) AS catScore, COUNT(DISTINCT f) AS userScore, COUNT(DISTINCT rel) AS relScore
// sum components
RETURN target, ratScore + catScore + userScore + relScore AS score
ORDER BY score DESC