Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

2014: John's Favorite Thing (Neo4j)

411 views

Published on

Given at BrooklynJS November 2014

Published in: Technology
  • Be the first to comment

  • Be the first to like this

2014: John's Favorite Thing (Neo4j)

  1. 1. 2014: John’s Favorite Thing
  2. 2. Problem:
 Art Photo Archives
  3. 3. Image Detail
  4. 4. Image Detail
  5. 5. Same Piece, Frame
  6. 6. Same Piece, Frame
  7. 7. Similar/Copies
  8. 8. Graph Analysis with Neo4j
  9. 9. Frick 420 420 Zeri 1583642090 Frick 417 417 ?
  10. 10. Frick 347 347 Zeri 12227 33526 Frick 348 348 33525 ?
  11. 11. 8132a 8132 57129 57134 57130 57138 8131a 8131 ?
  12. 12. Neo4j: Cypher
  13. 13. () ()
  14. 14. () ()- - >
  15. 15. What is a node? • A JSON document! • {“name”:”John”,”age”:30} • Can also have labels! • :human, :programmer, :corporeal
  16. 16. ({name:”John”}) ()- - >
  17. 17. ({name:”John”}) (:human)- - >
  18. 18. ({name”:”John}) (:cat)- - >
  19. 19. What is a relationship? • A JSON document! • {“first_met_date”:”2014-11-20”,”visits”:1} • Can have labels! • :owns, :is_friends_with, :spies_on
  20. 20. ({name:”John”}) ()-[:owns]- >
  21. 21. ({name:”John”}) ()-[:is_friends_with]- >
  22. 22. “Select” MATCH (a:Artwork {source: 'frick', century: 15})
 RETURN count(distinct a)
  23. 23. “JOIN” MATCH
 (a:Artwork {source: 'frick'})--(b:Artwork)
 RETURN a, b
  24. 24. Deep “JOIN” MATCH
 (a:Artwork {source: ‘frick’})-[*1..5]-(b:Artwork)
 RETURN a, b
  25. 25. “Find and Insert” MATCH (a:Artwork {id: 123}), (b:Artwork {id: 456}) CREATE (a)-[:is_similar_to]->(b);
  26. 26. “Update or Insert then Create” MERGE (artwork:Artwork {id: 123, source: ”frick”}) CREATE (image:Image {id: 456, source: “frick”}) CREATE (artwork)-[:photo]->(image);
  27. 27. Import data from CSV USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM "file://foo.csv" AS line MERGE (artwork:Artwork {id: line.artwork, source: line.source)}) CREATE (image:Image {id: line.image, source: line.source}) CREATE (artwork)-[:photo]->(image);
  28. 28. Frick 420 420 Zeri 1583642090 Frick 417 417 ?
  29. 29. Find the Missing Connection! MATCH
 (a:Artwork {source: 'frick'})--(i:Image)--
 (z:Image {source: 'zeri'})--
 (ii:Image)--(aa:Artwork {source: 'frick'})
 WHERE not(f=ff) AND not(a--aa)
 RETURN a,aa,i,ii,z
  30. 30. a aa ? MATCH
 (a:Artwork {source: 'frick'})--
 (i:Image)--
 (z:Image {source: 'zeri'})--
 (ii:Image)—
 (aa:Artwork {source: 'frick'})
 WHERE not(a=aa) AND not(i--ii)
 RETURN a,aa,i,ii,z i ii z
  31. 31. • http://ejohn.org/research/ • https://github.com/jeresig • http://neo4j.com/developer/cypher- query-language/ • http://neo4j.com/docs/2.0/cypher- refcard/

×