Loops in cypher

我的梦境 提交于 2019-12-11 06:11:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!