{"id":511,"date":"2019-07-29T20:52:11","date_gmt":"2019-07-29T20:52:11","guid":{"rendered":"http:\/\/172.31.10.168:8081\/blog\/index.php\/2019\/07\/29\/weighted-pagerank-algorithm-in-neo4j-using-cypher\/"},"modified":"2026-01-27T18:18:31","modified_gmt":"2026-01-27T18:18:31","slug":"weighted-pagerank-algorithm-in-neo4j-using-cypher","status":"publish","type":"post","link":"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511","title":{"rendered":"Weighted PageRank algorithm in Neo4j using Cypher"},"content":{"rendered":"<figure><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/cdn-images-1.medium.com\/max\/638\/1*7WQF7yXR3yoS8fZm8Bkpdg.jpeg\" alt=\"\" \/><\/figure>\n<p>PageRank is an algorithm used to measure the relative importance of nodes in a graph system. It is the underlying algorithm that determines what the 3.8 billion population of internet users experience on the web\u00a0today.<\/p>\n<figure><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/cdn-images-1.medium.com\/max\/630\/1*gQoEEvLdw8W3armVOsGpXg.jpeg\" alt=\"\" \/><figcaption>The size of each face is proportional to the total size of the other faces which are pointing to it. (source: Wikipedia)<\/figcaption><\/figure>\n<p>PageRank works great on an unweighted graph, i.e. it assumes that all the edges in the graph are of equal importance. However, there are a number of real world scenarios where the relationship between two nodes may differ based on its\u00a0nature.<\/p>\n<blockquote><p>If an article on Medium has links to two other independent web pages B &amp; C, the importance of the link may be inferred from where it is located in the article content ( Higher position =&gt; More important =&gt; more weight\u00a0).<\/p><\/blockquote>\n<h4><strong>Weighted PageRank<\/strong><\/h4>\n<p>In such scenarios, we need to resort to an edge-weighted graph and the PageRank algorithm can be modified to incorporate the edge weights in the calculation.<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/700\/1*-de804MzPtMB7FOoK2xc-Q.png\" alt=\"\" \/><figcaption>Weighted PageRank calculation. <em>The parameter d is a damping\u00a0factor<\/em><\/figcaption><\/figure>\n<p>PR_W(p) is the weighted pageRank of P. Here, W(P1.P) denotes the weight of edge from P1 to P, while \u03a3W(P1) is the total weight of all outgoing edges from P1. If this looks overwhelming to you, i\u2019d suggest you read about the basic pagerank calculation <a href=\"http:\/\/www.cs.princeton.edu\/~chazelle\/courses\/BIB\/pagerank.htm\">here<\/a>.<\/p>\n<p>Neo4j is one of the most popular graph databases today. Its intuitive modelling and simple query language (cypher) makes it very easy to represent any system as a Graph system. Neo4j does not provide PageRank computation out of the box, hence one needs to use a third party library <a href=\"https:\/\/github.com\/neo4j-contrib\/neo4j-apoc-procedures\">APOC<\/a> which provides a lot of graph algorithms including PageRank which can be run as cypher procedures in\u00a0Neo4j.<\/p>\n<p>However, the library does not have support for a Weighted PageRank algorithm. Hence, I decided to implement it in cypher, the code gist of which looks like this\u00a0\u2014<\/p>\n<p><iframe loading=\"lazy\" src=\"\/blog-test\/\" width=\"0\" height=\"0\" frameborder=\"0\" scrolling=\"no\"><a href=\"https:\/\/medium.com\/media\/b3935f0943c6f897a856fb45f9d9c4d6\/href\">https:\/\/medium.com\/media\/b3935f0943c6f897a856fb45f9d9c4d6\/href<\/a><\/iframe><\/p>\n<p>Now PageRank algorithm is inherently an iterative algorithms i.e. the algorithm needs to be iterated over the graph multiple times till the delta \u0394PR between successive iterations is negligible. I wrote a simple program in NodeJS that runs this cypher script iteratively and checks for the difference between successive iterations after each execution<\/p>\n<p>Voila! There we have our weighted PageRank algorithm. Have fun incorporating it into your own\u00a0graphs..<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/medium.com\/_\/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=696fe5519877\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PageRank is an algorithm used to measure the relative importance of nodes in a graph system. It is the underlying algorithm that determines what the 3.8 billion population of internet users experience on the web\u00a0today. The size of each face is proportional to the total size of the other faces which are pointing to it. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":533,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,13,17,22,27,30],"tags":[57],"class_list":["post-511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithms","category-cypher","category-data-visualization","category-graph","category-neo4j","category-pinned","tag-pinned"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog\" \/>\n<meta property=\"og:description\" content=\"PageRank is an algorithm used to measure the relative importance of nodes in a graph system. It is the underlying algorithm that determines what the 3.8 billion population of internet users experience on the web\u00a0today. The size of each face is proportional to the total size of the other faces which are pointing to it. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877\" \/>\n<meta property=\"og:site_name\" content=\"6figr.com Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-29T20:52:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-27T18:18:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"638\" \/>\n\t<meta property=\"og:image:height\" content=\"479\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"cto@6figr.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cto@6figr.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#article\",\"isPartOf\":{\"@id\":\"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511\"},\"author\":{\"name\":\"cto@6figr.com\",\"@id\":\"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed\"},\"headline\":\"Weighted PageRank algorithm in Neo4j using Cypher\",\"datePublished\":\"2019-07-29T20:52:11+00:00\",\"dateModified\":\"2026-01-27T18:18:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511\"},\"wordCount\":423,\"image\":{\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage\"},\"thumbnailUrl\":\"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg\",\"keywords\":[\"pinned\"],\"articleSection\":[\"algorithms\",\"cypher\",\"data-visualization\",\"graph\",\"neo4j\",\"pinned\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511\",\"url\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877\",\"name\":\"Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog\",\"isPartOf\":{\"@id\":\"https:\/\/6figr.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage\"},\"image\":{\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage\"},\"thumbnailUrl\":\"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg\",\"datePublished\":\"2019-07-29T20:52:11+00:00\",\"dateModified\":\"2026-01-27T18:18:31+00:00\",\"author\":{\"@id\":\"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed\"},\"breadcrumb\":{\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage\",\"url\":\"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg\",\"contentUrl\":\"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg\",\"width\":638,\"height\":479},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/6figr.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Weighted PageRank algorithm in Neo4j using Cypher\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/6figr.com\/blog\/#website\",\"url\":\"https:\/\/6figr.com\/blog\/\",\"name\":\"6figr.com Blog\",\"description\":\"Empowering Employees\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/6figr.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed\",\"name\":\"cto@6figr.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/6figr.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8fa19ea36a8718ece42824009585a769c3ae74426caeeb6661986b3d9ea7b7e1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8fa19ea36a8718ece42824009585a769c3ae74426caeeb6661986b3d9ea7b7e1?s=96&d=mm&r=g\",\"caption\":\"cto@6figr.com\"},\"sameAs\":[\"http:\/\/13.127.121.154\"],\"url\":\"https:\/\/6figr.com\/blog\/author\/cto6figr-com\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877","og_locale":"en_US","og_type":"article","og_title":"Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog","og_description":"PageRank is an algorithm used to measure the relative importance of nodes in a graph system. It is the underlying algorithm that determines what the 3.8 billion population of internet users experience on the web\u00a0today. The size of each face is proportional to the total size of the other faces which are pointing to it. [&hellip;]","og_url":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877","og_site_name":"6figr.com Blog","article_published_time":"2019-07-29T20:52:11+00:00","article_modified_time":"2026-01-27T18:18:31+00:00","og_image":[{"width":638,"height":479,"url":"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg","type":"image\/jpeg"}],"author":"cto@6figr.com","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cto@6figr.com","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#article","isPartOf":{"@id":"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511"},"author":{"name":"cto@6figr.com","@id":"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed"},"headline":"Weighted PageRank algorithm in Neo4j using Cypher","datePublished":"2019-07-29T20:52:11+00:00","dateModified":"2026-01-27T18:18:31+00:00","mainEntityOfPage":{"@id":"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511"},"wordCount":423,"image":{"@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage"},"thumbnailUrl":"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg","keywords":["pinned"],"articleSection":["algorithms","cypher","data-visualization","graph","neo4j","pinned"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/6figr.com\/blog\/weighted-pagerank-algorithm-in-neo4j-using-cypher-511","url":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877","name":"Weighted PageRank algorithm in Neo4j using Cypher - 6figr.com Blog","isPartOf":{"@id":"https:\/\/6figr.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage"},"image":{"@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage"},"thumbnailUrl":"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg","datePublished":"2019-07-29T20:52:11+00:00","dateModified":"2026-01-27T18:18:31+00:00","author":{"@id":"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed"},"breadcrumb":{"@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#primaryimage","url":"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg","contentUrl":"https:\/\/6figr.com\/blog\/wp-content\/uploads\/2019\/07\/1_7WQF7yXR3yoS8fZm8Bkpdg.jpg","width":638,"height":479},{"@type":"BreadcrumbList","@id":"https:\/\/medium.com\/@captainjackrana\/weighted-pagerank-algorithm-in-neo4j-using-cypher-696fe5519877#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/6figr.com\/blog"},{"@type":"ListItem","position":2,"name":"Weighted PageRank algorithm in Neo4j using Cypher"}]},{"@type":"WebSite","@id":"https:\/\/6figr.com\/blog\/#website","url":"https:\/\/6figr.com\/blog\/","name":"6figr.com Blog","description":"Empowering Employees","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/6figr.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/6figr.com\/blog\/#\/schema\/person\/a991acc57baccc3d803911228d7962ed","name":"cto@6figr.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/6figr.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8fa19ea36a8718ece42824009585a769c3ae74426caeeb6661986b3d9ea7b7e1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8fa19ea36a8718ece42824009585a769c3ae74426caeeb6661986b3d9ea7b7e1?s=96&d=mm&r=g","caption":"cto@6figr.com"},"sameAs":["http:\/\/13.127.121.154"],"url":"https:\/\/6figr.com\/blog\/author\/cto6figr-com"}]}},"_links":{"self":[{"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":1,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions\/534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/media\/533"}],"wp:attachment":[{"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/6figr.com\/blog\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}