diy graph search - max de marzi @ graphconnect boston + chicago 2013
DESCRIPTION
Facebook Graph Search has given the Graph Database community a simpler way to explain what it is we do and why it matters. I wanted to drive the point home by building a proof of concept of how you could do this with Neo4j.TRANSCRIPT
Innovate. Share. Connect.Chicago June 12-13
DIY Graph SearchMax De Marzi, Neo Technology
Tuesday, June 18, 13
Can I Haz?Tuesday, June 18, 13
NopeTuesday, June 18, 13
#9,998,383,750,000
Tuesday, June 18, 13
Can I make my own?
Tuesday, June 18, 13
MaybeTuesday, June 18, 13
What do I know about
NLP?Tuesday, June 18, 13
NothingTuesday, June 18, 13
What do I know?
Tuesday, June 18, 13
Tuesday, June 18, 13
andTuesday, June 18, 13
CypherTuesday, June 18, 13
I can query a graph
Tuesday, June 18, 13
How?Tuesday, June 18, 13
����������������� ���������������
Matching PatternsTuesday, June 18, 13
ASCII Art
Tuesday, June 18, 13
() --> ()
ASCII Art
Tuesday, June 18, 13
Named Nodes
Tuesday, June 18, 13
(A) --> (B)
Named Nodes
Tuesday, June 18, 13
LOVES
Typed Relationships
Tuesday, June 18, 13
A -[:LOVES]-> B
LOVES
Typed Relationships
Tuesday, June 18, 13
Describing a Path
Tuesday, June 18, 13
A --> B --> C
Describing a Path
Tuesday, June 18, 13
A
B C
Multiple Paths
Tuesday, June 18, 13
A --> B --> C, A --> C
A
B C
Multiple Paths
Tuesday, June 18, 13
A --> B --> C, A --> C
A
B C
A --> B --> C <-- A
Multiple Paths
Tuesday, June 18, 13
The START Clause
Tuesday, June 18, 13
The START Clause
START me=node(1)RETURN me
Tuesday, June 18, 13
with an Index
Tuesday, June 18, 13
with an Index
START me=node:Users(name=‘Max’)RETURN me
Tuesday, June 18, 13
The MATCH Clause
Tuesday, June 18, 13
The MATCH Clause
START me=node:Users(name=‘Max’)MATCH me -[:friends]-> peopleRETURN people
Tuesday, June 18, 13
My friends who like cheese
Tuesday, June 18, 13
My friends who like cheese
START me=node:Users(name=‘Max’) thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people -[:like]-> thingRETURN people
Tuesday, June 18, 13
My friends who like cheese
Tuesday, June 18, 13
My friends who like cheese
START me=node:Users(name=‘Max’) thing=node:Things(name=‘Cheese’)MATCH me -[:friends]-> people, people -[:like]-> thingRETURN people
Tuesday, June 18, 13
My friends who like ?
Tuesday, June 18, 13
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”}
Tuesday, June 18, 13
My friends who like ? and ?
Tuesday, June 18, 13
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”}
Tuesday, June 18, 13
People who like ? and ?
Tuesday, June 18, 13
People who like ? and ?START thing1=node:Things({thing1}), thing2=node:Things({thing2})MATCH people -[:like]-> thing1, people -[:like]-> thing2RETURN peopleParams :{“thing1”: “name: cheese”, “thing2”: “name: wine”}
Tuesday, June 18, 13
I need to build a Cypher Query
Tuesday, June 18, 13
SEMR
✦ Gateway drug to NLP
✦ 4 years old
✦ Didn’t work on my Mac
✦ Pointed me to Treetop
Tuesday, June 18, 13
Treetop✦ Create a Grammar by
making some Rules
✦ Turn expression into Syntax Tree
✦ Build custom Syntax Nodes
✦ Prune the tree
✦ to_cypher
Tuesday, June 18, 13
Friends Rule
Tuesday, June 18, 13
Friends Rule
rule friends “friends” <Friends>end
Tuesday, June 18, 13
friends to_cypher
Tuesday, June 18, 13
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
Tuesday, June 18, 13
Likes Rule
Tuesday, June 18, 13
Likes Rule
rule likes "who like" <Likes>end
Tuesday, June 18, 13
likes to_cypher
Tuesday, June 18, 13
likes to_cypher class Likes < Treetop::Runtime::SyntaxNode
def to_cypher
return {:match => "people -[:likes]-> thing"}
end
end
Tuesday, June 18, 13
Thing Rule
Tuesday, June 18, 13
Thing Rule
rule thing [a-zA-Z0-9]+ <Thing>end
Tuesday, June 18, 13
thing to_cypher
Tuesday, June 18, 13
thing to_cypherclass Thing < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing = node:things({thing})",
:params => {"thing" => "name: " + self.text_value } }
end
end
Tuesday, June 18, 13
Show and Tellhttps://github.com/maxdemarzi/neo_graph_search
http://maxdemarzi.com/2013/01/28/facebook-graph-search-with-cypher-and-neo4j/
Tuesday, June 18, 13