Fix BI Q25: sum relationship weight to get total path weight
-// Q25. Weighted paths
+// Q25. relationshipWeightsed paths
/*
:param {
person1Id: 19791209303405,
}
*/
MATCH
- path=allShortestPaths(
- (p1:Person {id: $person1Id})-[:KNOWS*]-(p2:Person {id: $person2Id})
- )
+ path=allShortestPaths((p1:Person {id: $person1Id})-[:KNOWS*]-(p2:Person {id: $person2Id}))
UNWIND relationships(path) AS k
WITH
path,
startNode(k) AS pA,
endNode(k) AS pB,
- 0 AS weight
+ 0 AS relationshipWeights
// A to B
// every reply (by one of the Persons) to a Post (by the other Person): 1.0
OPTIONAL MATCH
(pA)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(m:Post)-[:HAS_CREATOR]->(pB),
(m)<-[:CONTAINER_OF]-(forum:Forum)
WHERE forum.creationDate >= $startDate AND forum.creationDate <= $endDate
-WITH path, pA, pB, weight + count(c)*1.0 AS weight
+WITH path, pA, pB, relationshipWeights + count(c)*1.0 AS relationshipWeights
// A to B
// every reply (by ones of the Persons) to a Comment (by the other Person): 0.5
@@ -31,7 +29,7 @@ OPTIONAL MATCH
(pA)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(m:Comment)-[:HAS_CREATOR]->(pB),
(m)<-[:CONTAINER_OF]-(forum:Forum)
WHERE forum.creationDate >= $startDate AND forum.creationDate <= $endDate
-WITH path, pA, pB, weight + count(c)*0.5 AS weight
+WITH path, pA, pB, relationshipWeights + count(c)*0.5 AS relationshipWeights
// B to A
// every reply (by one of the Persons) to a Post (by the other Person): 1.0
@@ -39,7 +37,7 @@ OPTIONAL MATCH
(pB)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(m:Post)-[:HAS_CREATOR]->(pA),
(m)<-[:CONTAINER_OF]-(forum:Forum)
WHERE forum.creationDate >= $startDate AND forum.creationDate <= $endDate
-WITH path, pA, pB, weight + count(c)*1.0 AS weight
+WITH path, pA, pB, relationshipWeights + count(c)*1.0 AS relationshipWeights
// B to A
// every reply (by ones of the Persons) to a Comment (by the other Person): 0.5
@@ -47,9 +45,13 @@ OPTIONAL MATCH
(pB)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(m:Comment)-[:HAS_CREATOR]->(pA),
(m)<-[:CONTAINER_OF]-(forum:Forum)
WHERE forum.creationDate >= $startDate AND forum.creationDate <= $endDate
-WITH path, pA, pB, weight + count(c)*0.5 AS weight
+WITH path, pA, pB, relationshipWeights + count(c)*0.5 AS relationshipWeights
+
+WITH
+ [person IN nodes(path) | person.id] AS personIds,
+ sum(relationshipWeights) AS weight
RETURN
- [person IN nodes(path) | person.id] AS personIds
+ personIds
ORDER BY
weight DESC
