letme’graph’thatfor’youjaoo.dk/dl/goto-amsterdam-2014/slides/ianrobinson_letmegraphth… ·...

42
@neo4j Let Me Graph That For You @ianSrobinson [email protected]

Upload: others

Post on 24-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Let  Me  Graph  That  For  You  

@ianSrobinson  [email protected]  

 

Page 2: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

complexity = f(size, variable structure, connectedness)  

Page 3: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Graphs  Are  Everywhere  

Page 4: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

•  Store  •  Manage  •  Query   data  

Graph  Databases  

Page 5: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Neo4j  is  a  Graph  Database  

Page 6: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Labeled  Property  Graph  

Page 7: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Making  ConnecIons  

Page 8: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Triadic  Closure  –  Closing  Triangles  

Page 9: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Triadic  Closure  –  Closing  Triangles  

Page 10: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Triadic  Closure  –  Closing  Triangles  

Page 11: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Recommending  New  ConnecIons  

Page 12: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Immediate  Friendships  

Page 13: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Means  and  MoIve  

Page 14: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

RecommendaIon  

Page 15: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Recommend  New  ConnecIons  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 16: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Find  Terry  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 17: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Find  Terry’s  Friends’  Friends  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 18: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Find  Terry’s  Friends’  Friends  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 19: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

…Who  Terry  Doesn’t  Know  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 20: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Count  Matches  Per  Person  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 21: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Return  The  Results  MATCH (user:User{name:'Terry'}) -[:FRIEND*2]- (other:User)WHERE NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 22: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Taking  Account  of  Friendship  Strength  

MATCH (user:User{name:'Terry'}) -[rels:FRIEND*2]- (other:User)WHERE ALL(r IN rels WHERE r.strength > 1)AND NOT (user)-[:FRIEND]-(other)RETURN other.name AS name, COUNT(other) AS scoreORDER BY score DESC

Page 23: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Nowhere  To  Hide  

Page 24: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

First-­‐Party  Fraud  

•  Fraudsters  apply  for  credit  – No  intenIon  of  repaying  

•  Appear  normal  unIl  they  “burst  out”  – Clear  out  accounts  

•  Fraud  ring  – Share  bits  of  idenIty  (NI,  address,  telephone)  – Coordinated  “burst  out”  

Page 25: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Fraud  Ring  

Page 26: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Query  

•  Create  new  applicant    •  Connect  applicant  to  idenIty  info  – Reuse  exisIng  idenIfy  info  where  possible  

Then  •  Select  applicant’s  idenIty  info  •  Crawl  surrounding  graph  – Look  for  expansive  clusters  of  account  holders  

Page 27: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Path  CalculaIons  

Page 28: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Problem  

•  Increase  in  parcel  traffic  – Amazon,  eBay  –  Current  infrastructure  can’t  cope  

•  Calculate  opImal  route  – Under  40ms  –  Routes  vary  over  Ime  

•  Numbers:  –  2000-­‐3000  parcels  per  second  –  25  naIonal  parcel  centres,  2  million  postcodes,  30  million  address  

Page 29: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Period  1  

Page 30: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Period  2  

Page 31: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Period  3  

Page 32: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

The  Full  Graph  

Page 33: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Page 34: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Steps  1  and  2  

Page 35: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Step  3  

Page 36: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Paths  MATCH path=(from{name:'X'}) -[:CONNECTED_TO*1..4]-> (to{name:'Y'})RETURN path AS shortestPath, reduce(weight=0, r in relationships(path) | weight + r.weight) AS totalORDER BY total ASCLIMIT 1

Page 37: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Match  Variable-­‐Length  Path  MATCH path=(from{name:'X'}) -[:CONNECTED_TO*1..4]-> (to{name:'Y'})RETURN path AS shortestPath, reduce(weight=0, r in relationships(path) | weight + r.weight) AS totalORDER BY total ASCLIMIT 1

Page 38: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Calculate  Path  Weight  MATCH path=(from{name:'X'}) -[:CONNECTED_TO*1..4]-> (to{name:'Y'})RETURN path AS shortestPath, reduce(weight=0, r in relationships(path) | weight + r.weight) AS totalORDER BY total ASCLIMIT 1

Page 39: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Return  Shortest  Weighted  Path  MATCH path=(from{name:'X'}) -[:CONNECTED_TO*1..4]-> (to{name:'Y'})RETURN path AS shortestPath, reduce(weight=0, r in relationships(path) | weight + r.weight) AS totalORDER BY total ASCLIMIT 1

Page 40: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Full  Query  MATCH (s:Location {name:{startLocation}}), (e:Location {name:{endLocation}})MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1)WHERE all(r in relationships(upLeg) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})WITH e, upLeg, db1MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)WHERE all(r in relationships(downLeg) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})WITH db1, db2, upLeg, downLegMATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)WHERE all(r in relationships(topRoute) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})WITH upLeg, downLeg, topRoute, reduce(weight=0, r in relationships(topRoute) | weight+r.cost) AS score ORDER BY score ASC LIMIT 1RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS route

Page 41: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

neo4j.com/online_course  

Page 42: LetMe’Graph’ThatFor’Youjaoo.dk/dl/goto-amsterdam-2014/slides/IanRobinson_LetMeGraphTh… · @neo4j’ LetMe’Graph’ThatFor’You ’ @ianSrobinson’ ian@neotechnology.com’

@neo4j  

Ian Robinson, Jim Webber & Emil Eifrem

Graph Databases

h

Compliments

of Neo Technology

graphdatabases.com  

@ianSrobinson  #neo4j  

   

Thank  you