facebook graph search with cypher and neo4j
DESCRIPTION
How to build your own Facebook Graph Search with Cypher and Neo4j. Demo: neographsearch.herokuapp.com Blog post: http://maxdemarzi.com/2013/01/28/facebook-graph-search-with-cypher-and-neo4j/ Github: https://github.com/maxdemarzi/neo_graph_searchTRANSCRIPT
![Page 1: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/1.jpg)
Facebook Graph Search with Neo4j
Max De Marzi
Monday, April 29, 13
![Page 2: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/2.jpg)
Can I Haz?Monday, April 29, 13
![Page 3: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/3.jpg)
NopeMonday, April 29, 13
![Page 4: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/4.jpg)
#9,998,383,750,000
Monday, April 29, 13
![Page 5: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/5.jpg)
Can I make my own?
Monday, April 29, 13
![Page 6: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/6.jpg)
MaybeMonday, April 29, 13
![Page 7: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/7.jpg)
What do I know about
NLP?Monday, April 29, 13
![Page 8: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/8.jpg)
NothingMonday, April 29, 13
![Page 9: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/9.jpg)
What do I know?
Monday, April 29, 13
![Page 10: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/10.jpg)
Monday, April 29, 13
![Page 11: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/11.jpg)
andMonday, April 29, 13
![Page 12: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/12.jpg)
CypherMonday, April 29, 13
![Page 13: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/13.jpg)
I can query a graph
Monday, April 29, 13
![Page 14: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/14.jpg)
How?Monday, April 29, 13
![Page 15: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/15.jpg)
����������������� ���������������
Matching PatternsMonday, April 29, 13
![Page 16: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/16.jpg)
ASCII Art
Monday, April 29, 13
![Page 17: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/17.jpg)
() --> ()
ASCII Art
Monday, April 29, 13
![Page 18: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/18.jpg)
Named Nodes
Monday, April 29, 13
![Page 19: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/19.jpg)
(A) --> (B)
Named Nodes
Monday, April 29, 13
![Page 20: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/20.jpg)
LOVES
Typed Relationships
Monday, April 29, 13
![Page 21: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/21.jpg)
A -[:LOVES]-> B
LOVES
Typed Relationships
Monday, April 29, 13
![Page 22: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/22.jpg)
Describing a Path
Monday, April 29, 13
![Page 23: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/23.jpg)
A --> B --> C
Describing a Path
Monday, April 29, 13
![Page 24: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/24.jpg)
A
B C
Multiple Paths
Monday, April 29, 13
![Page 25: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/25.jpg)
A --> B --> C, A --> C
A
B C
Multiple Paths
Monday, April 29, 13
![Page 26: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/26.jpg)
A --> B --> C, A --> C
A
B C
A --> B --> C <-- A
Multiple Paths
Monday, April 29, 13
![Page 27: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/27.jpg)
The START Clause
Monday, April 29, 13
![Page 28: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/28.jpg)
The START Clause
START me=node(1)RETURN me
Monday, April 29, 13
![Page 29: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/29.jpg)
with an Index
Monday, April 29, 13
![Page 30: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/30.jpg)
with an Index
START me=node:Users(name=‘Max’)RETURN me
Monday, April 29, 13
![Page 31: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/31.jpg)
The MATCH Clause
Monday, April 29, 13
![Page 32: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/32.jpg)
The MATCH Clause
START me=node:Users(name=‘Max’)MATCH me -[:friends]-> peopleRETURN people
Monday, April 29, 13
![Page 33: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/33.jpg)
My friends who like cheese
Monday, April 29, 13
![Page 34: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/34.jpg)
My friends who like cheese
START me=node:Users(name=‘Max’) thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people -[:like]-> thingRETURN people
Monday, April 29, 13
![Page 35: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/35.jpg)
My friends who like cheese
Monday, April 29, 13
![Page 36: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/36.jpg)
My friends who like cheese
START me=node:Users(name=‘Max’) thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people, people -[:like]-> thingRETURN people
Monday, April 29, 13
![Page 37: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/37.jpg)
My friends who like ?
Monday, April 29, 13
![Page 38: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/38.jpg)
My friends who like ?START me=node({me}), thing=node:Things({thing})MATCH me -[:friends]-> people, people -[:like]-> thingRETURN people
Params :{“me”: 1, “thing”: “name: cheese”}
Monday, April 29, 13
![Page 39: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/39.jpg)
My friends who like ? and ?
Monday, April 29, 13
![Page 40: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/40.jpg)
My friends who like ? and ?
START me=node({me}), thing1=node:Things({thing1}), thing2=node:Things({thing2})MATCH me -[:friends]-> people, people -[:like]-> thing1, people -[:like]-> thing2RETURN peopleParams :{“me”: 1, “thing1”: “name: cheese”, “thing2”: “name: wine”}
Monday, April 29, 13
![Page 41: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/41.jpg)
I need to build a Cypher Query
Monday, April 29, 13
![Page 42: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/42.jpg)
SEMR
✦ Gateway drug to NLP
✦ 4 years old
✦ Didn’t work on my Mac
✦ Pointed me to Treetop
Monday, April 29, 13
![Page 43: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/43.jpg)
Treetop✦ Create a Grammar by
making some Rules
✦ Turn expression into Syntax Tree
✦ Build custom Syntax Nodes
✦ Prune the tree
✦ to_cypher
Monday, April 29, 13
![Page 44: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/44.jpg)
Friends Rule
Monday, April 29, 13
![Page 45: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/45.jpg)
Friends Rule
rule friends “friends” <Friends>end
Monday, April 29, 13
![Page 46: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/46.jpg)
friends to_cypher
Monday, April 29, 13
![Page 47: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/47.jpg)
friends to_cypher class Friends < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "me = node({me})",
:match => "me -[:friends]-> people",
:return => "people",
:params => {"me" => nil }}
end
end
Monday, April 29, 13
![Page 48: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/48.jpg)
Likes Rule
Monday, April 29, 13
![Page 49: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/49.jpg)
Likes Rule
rule likes "who like" <Likes>end
Monday, April 29, 13
![Page 50: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/50.jpg)
likes to_cypher
Monday, April 29, 13
![Page 51: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/51.jpg)
likes to_cypher class Likes < Treetop::Runtime::SyntaxNode
def to_cypher
return {:match => "people -[:likes]-> thing"}
end
end
Monday, April 29, 13
![Page 52: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/52.jpg)
Thing Rule
Monday, April 29, 13
![Page 53: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/53.jpg)
Thing Rule
rule thing [a-zA-Z0-9]+ <Thing>end
Monday, April 29, 13
![Page 54: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/54.jpg)
thing to_cypher
Monday, April 29, 13
![Page 55: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/55.jpg)
thing to_cypherclass Thing < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing = node:things({thing})",
:params => {"thing" => "name: " + self.text_value } }
end
end
Monday, April 29, 13
![Page 56: Facebook Graph Search with Cypher and Neo4j](https://reader037.vdocuments.us/reader037/viewer/2022110306/554f64b6b4c9058a148b4a36/html5/thumbnails/56.jpg)
Show and Tellhttps://github.com/maxdemarzi/neo_graph_search
http://maxdemarzi.com/2013/01/28/facebook-graph-search-with-cypher-and-neo4j/
Monday, April 29, 13