问题
The following algorithm finds the page rank (note that this is a tweaked version of page rank algorithm):
/* we have to go through all nodes */
MATCH (node:Page)
WITH
COLLECT(distinct node) AS pages
UNWIND pages as dest
/* let's find all source citations for a given node */
MATCH (source:Page)-[:NEXT]->(dest)
WITH
COLLECT(DISTINCT source) AS sources,
dest AS dest
UNWIND sources AS src
/* we have to know how many relationships the source node has */
MATCH (src)-[r:NEXT]->(dest)
WITH src, dest, sum(r.weight) AS prob
MATCH (src)-[r:NEXT]->()
WITH
/* The source citation will pass a portion of its pagerank as juice */
src.pagerank * (prob/ sum(r.weight)) AS juice,
dest AS dest
/* now we have all information to update the destination node with the new pagerank */
WITH
sum(juice) AS p,
dest AS dest
/* Using damping factor d = 0.85 */
set dest.pagerank = 0.15 + 0.85 * p;
Now for a given graph:
LOAD CSV WITH HEADERS FROM "file:\\graphUnioned1.csv" AS csvLine
MERGE (s:Node {value:csvLine.s})
MERGE (o:Node {value:csvLine.o})
MERGE (s)-[:REL {weight: toFloat(csvLine.p)}]->(o);
How do I find the page rank of all nodes in the graph. I want to run the above pagerank algorithm iteratively till 100 iterations
来源:https://stackoverflow.com/questions/54631857/loops-in-cypher