ConnectedData @ian S robinson ian@neotechnology.com Neo4j - - PowerPoint PPT Presentation

connecteddata
SMART_READER_LITE
LIVE PREVIEW

ConnectedData @ian S robinson ian@neotechnology.com Neo4j - - PowerPoint PPT Presentation

New Opportuni-es for ConnectedData @ian S robinson ian@neotechnology.com Neo4j Graph Database complexity = f(size, variable structure, connectedness) How Do Graphs Help


slide-1
SLIDE 1

New ¡Opportuni-es ¡for ¡ ConnectedData ¡

@ianSrobinson ¡ ian@neotechnology.com ¡ ¡

slide-2
SLIDE 2

Neo4j ¡Graph ¡Database ¡

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5

complexity = f(size, variable structure, connectedness) ¡

slide-6
SLIDE 6

How ¡Do ¡Graphs ¡Help ¡

  • Represent ¡and ¡navigate ¡a ¡variably-­‑structured ¡

domain ¡

  • Understand ¡which ¡things ¡are ¡connected, ¡how, ¡

and ¡with ¡what ¡strength, ¡weight ¡or ¡quality ¡

slide-7
SLIDE 7

Variable ¡Structure ¡

  • Rela-onships ¡provide ¡structure ¡
  • Importantly, ¡they ¡are ¡defined ¡with ¡regard ¡to ¡

node ¡instances, ¡not ¡classes ¡of ¡nodes ¡

slide-8
SLIDE 8

Connectedness ¡

Rela%onship ¡Names ¡

  • Seman-cs ¡first-­‑class ¡element ¡in ¡data ¡model ¡

Rela%onship ¡Proper%es ¡

  • Describe ¡weight, ¡strength ¡or ¡quality ¡of ¡a ¡

rela-onship ¡

slide-9
SLIDE 9

Making ¡Connec-ons ¡

slide-10
SLIDE 10

Triadic ¡Closure ¡– ¡Closing ¡Triangles ¡

slide-11
SLIDE 11

Triadic ¡Closure ¡– ¡Closing ¡Triangles ¡

slide-12
SLIDE 12

Triadic ¡Closure ¡– ¡Closing ¡Triangles ¡

slide-13
SLIDE 13

Recommending ¡New ¡Connec-ons ¡

slide-14
SLIDE 14

Immediate ¡Friendships ¡

slide-15
SLIDE 15

Means ¡and ¡Mo-ve ¡

slide-16
SLIDE 16

Recommenda-on ¡

slide-17
SLIDE 17

Recommend ¡New ¡Connec-ons ¡

MATCH (user:User{name:'Terry'})

  • [:FRIEND*2]-

(other:User) WHERE NOT (user)-[:FRIEND]-(other) RETURN other.name AS name, COUNT(other) AS score ORDER BY score DESC

slide-18
SLIDE 18

Find ¡Terry ¡

MATCH ( MATCH (user:User user:User{name:'Terry name:'Terry'}) '})

  • [:FRIEND*2]-

(other:User) WHERE NOT (user)-[:FRIEND]-(other) RETURN other.name AS name, COUNT(other) AS score ORDER BY score DESC

slide-19
SLIDE 19

Find ¡Terry’s ¡Friends’ ¡Friends ¡

MATCH (user:User{name:'Terry'})

  • [:FRIEND*2]-
  • [:FRIEND*2]-

( (other:User

  • ther:User)

WHERE NOT (user)-[:FRIEND]-(other) RETURN other.name AS name, COUNT(other) AS score ORDER BY score DESC

slide-20
SLIDE 20

Find ¡Terry’s ¡Friends’ ¡Friends ¡

MATCH ( MATCH (user:User user:User{name:'Terry name:'Terry'}) '})

  • [:FRIEND*2]-
  • [:FRIEND*2]-

( (other:User

  • ther:User)

WHERE NOT (user)-[:FRIEND]-(other) RETURN other.name AS name, COUNT(other) AS score ORDER BY score DESC

slide-21
SLIDE 21

…Who ¡Terry ¡Doesn’t ¡Know ¡

MATCH (user:User{name:'Terry'})

  • [:FRIEND*2]-

(other:User) WHERE NOT (user)-[:FRIEND]-(other) WHERE NOT (user)-[:FRIEND]-(other) RETURN other.name AS name, COUNT(other) AS score ORDER BY score DESC

slide-22
SLIDE 22

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 score COUNT(other) AS score ORDER BY score DESC

slide-23
SLIDE 23

Return ¡The ¡Results ¡

MATCH (user:User{name:'Terry'})

  • [:FRIEND*2]-

(other:User) WHERE NOT (user)-[:FRIEND]-(other) RETURN RETURN other.name

  • ther.name AS name,

AS name, COUNT(other) AS score COUNT(other) AS score ORDER BY score DESC ORDER BY score DESC

slide-24
SLIDE 24

Taking ¡Account ¡of ¡Friendship ¡Strength ¡

MATCH (user:User{name:'Terry'})

  • [
  • [rels:FRIEND

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

slide-25
SLIDE 25

Nowhere ¡To ¡Hide ¡

slide-26
SLIDE 26

First-­‑Party ¡Fraud ¡

  • Fraudsters ¡apply ¡for ¡credit ¡

– No ¡inten-on ¡of ¡repaying ¡

  • Appear ¡normal ¡un-l ¡they ¡“burst ¡out” ¡

– Clear ¡out ¡accounts ¡

  • Fraud ¡ring ¡

– Share ¡bits ¡of ¡iden-ty ¡(NI, ¡address, ¡telephone) ¡ – Coordinated ¡“burst ¡out” ¡

slide-27
SLIDE 27

Fraud ¡Ring ¡

slide-28
SLIDE 28

Query ¡

  • Create ¡new ¡applicant ¡ ¡
  • Connect ¡applicant ¡to ¡iden-ty ¡info ¡

– Reuse ¡exis-ng ¡iden-fy ¡info ¡where ¡possible ¡

Then ¡

  • Select ¡applicant’s ¡iden-ty ¡info ¡
  • Crawl ¡surrounding ¡graph ¡

– Look ¡for ¡expansive ¡clusters ¡of ¡account ¡holders ¡

slide-29
SLIDE 29

Path ¡Calcula-ons ¡

slide-30
SLIDE 30

Problem ¡

  • Increase ¡in ¡parcel ¡traffic ¡

– Amazon, ¡eBay ¡ – Current ¡infrastructure ¡can’t ¡cope ¡

  • Calculate ¡op-mal ¡route ¡

– Under ¡20ms ¡ – Routes ¡vary ¡over ¡-me ¡

  • Numbers: ¡

– 2000-­‑3000 ¡parcels ¡per ¡second ¡ – 25 ¡na-onal ¡parcel ¡centres, ¡2 ¡million ¡postcodes, ¡30 ¡ million ¡address ¡

slide-31
SLIDE 31

Period ¡1 ¡

slide-32
SLIDE 32

Period ¡2 ¡

slide-33
SLIDE 33

Period ¡3 ¡

slide-34
SLIDE 34

The ¡Full ¡Graph ¡

slide-35
SLIDE 35
slide-36
SLIDE 36

Steps ¡1 ¡and ¡2 ¡

slide-37
SLIDE 37

Find ¡Start ¡and ¡End ¡

MATCH (s:Location {name:{startLocation}}), (e:Location {name:{endLocation}})

slide-38
SLIDE 38

Calculate ¡Up ¡Leg ¡

MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1) WHERE all(r in relationships(upLeg) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})

slide-39
SLIDE 39

Path ¡From ¡Start ¡to ¡a ¡Delivery ¡Base ¡

MATCH MATCH upLeg upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1) = (s)<-[:DELIVERY_ROUTE*1..2]-(db1) WHERE all(r in relationships(upLeg) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})

slide-40
SLIDE 40

Filter ¡Rela-onships ¡by ¡Period ¡

MATCH upLeg = (s)<-[:DELIVERY_ROUTE*1..2]-(db1) WHERE all(r in relationships( WHERE all(r in relationships(upLeg upLeg) WHERE WHERE r.start_date r.start_date <= { <= {intervalStart intervalStart} AND AND r.end_date r.end_date >= { >= {intervalEnd intervalEnd}) })

slide-41
SLIDE 41

Calculate ¡Down ¡Path ¡

WITH e, upLeg, db1 MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e) WHERE all(r in relationships(downLeg) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})

slide-42
SLIDE 42

Step ¡3 ¡

slide-43
SLIDE 43

Find ¡Routes ¡Between ¡Delivery ¡Bases ¡

WITH db1, db2, upLeg, downLeg MATCH 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})

slide-44
SLIDE 44

Paths ¡Between ¡Delivery ¡Bases ¡

WITH db1, db2, upLeg, downLeg MATCH MATCH topRoute topRoute = = (db1)<-[:CONNECTED_TO]-() (db1)<-[:CONNECTED_TO]-()

  • [:CONNECTED_TO*1..3]-(db2)
  • [:CONNECTED_TO*1..3]-(db2)

WHERE all(r in relationships(topRoute) WHERE r.start_date <= {intervalStart} AND r.end_date >= {intervalEnd})

slide-45
SLIDE 45

Filtered ¡by ¡Period ¡

WITH db1, db2, upLeg, downLeg MATCH topRoute = (db1)<-[:CONNECTED_TO]-()

  • [:CONNECTED_TO*1..3]-(db2)

WHERE all(r in relationships( WHERE all(r in relationships(topRoute topRoute) WHERE WHERE r.start_date r.start_date <= { <= {intervalStart intervalStart} AND AND r.end_date r.end_date >= { >= {intervalEnd intervalEnd}) })

slide-46
SLIDE 46

Calculate ¡Shortest ¡Route ¡Between ¡ Delivery ¡Bases ¡

WITH upLeg, downLeg, topRoute, reduce ( weight=0, r in relationships(topRoute) | weight+r.cost) AS score ORDER BY score ASC LIMIT 1 RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS route

slide-47
SLIDE 47

Calculate ¡Shortest ¡Path ¡Between ¡ Delivery ¡Bases ¡

WITH upLeg, downLeg, topRoute, reduce ( reduce ( weight=0, weight=0, r in relationships( r in relationships(topRoute topRoute) | ) | weight+r.cost weight+r.cost) AS score ) AS score ORDER BY score ASC ORDER BY score ASC LIMIT 1 LIMIT 1 RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS route

slide-48
SLIDE 48

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, db1 MATCH 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, downLeg MATCH 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 1 RETURN (nodes(upLeg) + tail(nodes(topRoute)) + tail(nodes(downLeg))) AS route

slide-49
SLIDE 49

Online ¡Training ¡

hgp://www.neo4j.org/learn/online_course ¡

slide-50
SLIDE 50

Graph ¡Gists ¡

hgps://github.com/neo4j-­‑contrib/graphgist/wiki ¡

slide-51
SLIDE 51

Ian Robinson, Jim Webber & Emil Eifrem

Graph Databases h

Compliments

  • f Neo Technology

graphdatabases.com ¡