facebook graph search with cypher and neo4j

Post on 10-May-2015

2.792 Views

Category:

Business

0 Downloads

Preview:

Click to see full reader

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_search

TRANSCRIPT

Facebook Graph Search with Neo4j

Max De Marzi

Monday, April 29, 13

Can I Haz?Monday, April 29, 13

NopeMonday, April 29, 13

#9,998,383,750,000

Monday, April 29, 13

Can I make my own?

Monday, April 29, 13

MaybeMonday, April 29, 13

What do I know about

NLP?Monday, April 29, 13

NothingMonday, April 29, 13

What do I know?

Monday, April 29, 13

Monday, April 29, 13

andMonday, April 29, 13

CypherMonday, April 29, 13

I can query a graph

Monday, April 29, 13

How?Monday, April 29, 13

����������������� ���������������

Matching PatternsMonday, April 29, 13

ASCII Art

Monday, April 29, 13

() --> ()

ASCII Art

Monday, April 29, 13

Named Nodes

Monday, April 29, 13

(A) --> (B)

Named Nodes

Monday, April 29, 13

LOVES

Typed Relationships

Monday, April 29, 13

A -[:LOVES]-> B

LOVES

Typed Relationships

Monday, April 29, 13

Describing a Path

Monday, April 29, 13

A --> B --> C

Describing a Path

Monday, April 29, 13

A

B C

Multiple Paths

Monday, April 29, 13

A --> B --> C, A --> C

A

B C

Multiple Paths

Monday, April 29, 13

A --> B --> C, A --> C

A

B C

A --> B --> C <-- A

Multiple Paths

Monday, April 29, 13

The START Clause

Monday, April 29, 13

The START Clause

START me=node(1)RETURN me

Monday, April 29, 13

with an Index

Monday, April 29, 13

with an Index

START me=node:Users(name=‘Max’)RETURN me

Monday, April 29, 13

The MATCH Clause

Monday, April 29, 13

The MATCH Clause

START me=node:Users(name=‘Max’)MATCH me -[:friends]-> peopleRETURN people

Monday, April 29, 13

My friends who like cheese

Monday, April 29, 13

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

My friends who like cheese

Monday, April 29, 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

Monday, April 29, 13

My friends who like ?

Monday, April 29, 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”}

Monday, April 29, 13

My friends who like ? and ?

Monday, April 29, 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”}

Monday, April 29, 13

I need to build a Cypher Query

Monday, April 29, 13

SEMR

✦ Gateway drug to NLP

✦ 4 years old

✦ Didn’t work on my Mac

✦ Pointed me to Treetop

Monday, April 29, 13

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

Friends Rule

Monday, April 29, 13

Friends Rule

rule friends “friends” <Friends>end

Monday, April 29, 13

friends to_cypher

Monday, April 29, 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

Monday, April 29, 13

Likes Rule

Monday, April 29, 13

Likes Rule

rule likes "who like" <Likes>end

Monday, April 29, 13

likes to_cypher

Monday, April 29, 13

likes to_cypher class Likes < Treetop::Runtime::SyntaxNode

def to_cypher

return {:match => "people -[:likes]-> thing"}

end

end

Monday, April 29, 13

Thing Rule

Monday, April 29, 13

Thing Rule

rule thing [a-zA-Z0-9]+ <Thing>end

Monday, April 29, 13

thing to_cypher

Monday, April 29, 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

Monday, April 29, 13

top related