Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit c7a0c54

Browse files
tomasonjojexp
authored andcommitted
Add pagerank yelp example (#429)
1 parent 9a234a6 commit c7a0c54

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

doc/pagerank.adoc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Dead-ends problem occurs, when pages have no out links.
5959
Sometimes a page contains a link of another page which has no out links.
6060
These types of link are known as dangling links.[1]
6161

62+
Check reference http://www.cs.princeton.edu/~chazelle/courses/BIB/pagerank.htm[[7\]] for more.
63+
6264

6365
== Algorithm explanation on simple sample graph
6466

@@ -103,11 +105,23 @@ As we expected, we see that Home page has the highest pageRank, because it has i
103105

104106
== Example Usage
105107

106-
.minimal
108+
In short PageRank is a “vote”, by all the other nodes in the graph, about how important a node is. A relationship to a node counts as a vote of support. If there’s no link there’s no support (but it’s an abstention from voting rather than a vote against the node).[7]
109+
110+
We have to add here that the weight of the support from one node to another is related to how important the "voter" node is.
111+
112+
We will run PageRank on Yelp's social network to find potential influencers.
113+
If you will check closely you can see that we saved the social network as an undirected graph.
114+
For now there is no option to load the the relationship as undirected, but we can use cypher loading to help us solve this.
115+
Undirected graph can be represented as https://en.wikipedia.org/wiki/Bidirected_graph[Bidirected graph], that is a directed graph in which the reverse of every relationship is also a relationship.
116+
117+
We do not have to save this reversed relationship, we can project it using *cypher loading*.
118+
We load all relationships and then use `UNION` to also load all relationships with reversed directions.
119+
This is applicable to all other algorithms, that use *cypher loading*.
120+
121+
.Running algorithm on Yelp social network
107122
[source,cypher]
108123
----
109-
CALL algo.pageRank('Label1', 'TYPE1') YIELD computeMillis
110-
CALL algo.pageRank.stream('Label1', 'TYPE1') YIELD node, score order by score desc limit 20
124+
include::scripts/pagerank.cypher[tag=pagerank-stream-yelp-social]
111125
----
112126

113127
== Syntax
@@ -208,8 +222,6 @@ We support the following versions of the pageRank algorithm:
208222

209223
* http://infolab.stanford.edu/~ullman/mmds/book.pdf
210224

211-
* http://www.cs.princeton.edu/~chazelle/courses/BIB/pagerank.htm
212-
213225
* https://anthonybonato.com/2016/04/13/the-mathematics-of-game-of-thrones/
214226

215227
* [1] http://research.ijcaonline.org/volume110/number12/pxc3901035.pdf
@@ -224,6 +236,8 @@ We support the following versions of the pageRank algorithm:
224236

225237
* [6] https://bmcbioinformatics.biomedcentral.com/track/pdf/10.1186/1471-2105-15-204?site=bmcbioinformatics.biomedcentral.com
226238

239+
* [7] http://www.cs.princeton.edu/~chazelle/courses/BIB/pagerank.htm
240+
227241
ifdef::implementation[]
228242
// tag::implementation[]
229243

doc/scripts/yelp-import.cypher

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,15 @@ ON CREATE SET cr.weight = weight
104104

105105
// end::coocurence-graph[]
106106

107-
107+
// tag:pagerank-stream-yelp-social[]
108+
109+
call algo.pageRank.stream(
110+
'MATCH (u:User) WHERE exists( (u)-[:FRIENDS]-() ) RETURN id(u) as id',
111+
'MATCH (u1:User)-[:FRIENDS]->(u2:User) RETURN id(u1) as source, id(u2) as target
112+
UNION
113+
MATCH (u1:User)-[:FRIENDS]->(u2:User) RETURN id(u2) as source, id(u1) as target',
114+
{graph:'cypher'}
115+
) yield node,score with node,score order by score desc limit 10
116+
return node {.name, .review_count, .average_stars,.useful,.yelping_since,.funny},score;
117+
118+
// end:pagerank-stream-yelp-social[]

0 commit comments

Comments
 (0)