Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Intro to Neo4j
@praveenasekhar / @markneedham
<3
Tweet us your pictures
@neo4j
@WomenWhoCode
Welcome!
Logistics
‣ Wi-fi
• network: LNVisitor
• user/password: LNGuest / LNGuest
‣ Grab a USB key from one of the tables or
downl...
They GoT the title wrong ...
There maybe spoilers.. [Maybe]
Example
Game of Thrones Wiki
By the end you will help us work out
‣ Who is the most prominent character in a
season?
‣ Which house features the most ch...
A quick show of hands...
How many people have used
databases before?
A quick show of hands...
How many people have used
Neo4j before?
A quick show of hands...
How many people have
watched Game of Thrones?
Whiteboard / Post-It Exercise
Everyone!
List down different types of entities and
relationships that tie them in the Game ...
‣ Actors
‣ Characters
‣ Allegiances
‣ Houses
‣ Episodes
‣ Locations
What data do we have?
‣ An introduction to Neo4j and the Cypher
query language
‣ GoT characters and episodes
‣ GoT houses
‣ GoT family relations...
Example
A brief into to the
graph data model
GoT graph model
Nodes
Labels
Properties
Relationships
Introducing Cypher
What is Cypher?
‣ The graph query language
‣ Declarative and based on finding patterns
‣ ASCII Art + Query Language = Cyph...
Nodes
() or (n)
● Surrounded with parentheses
● Use an alias to refer to our node later
(n:Label)
● Specify a Label - grou...
Relationships
--> or -[:TYPE]->
● Hyphenated & encased in square brackets
● Like labels, a relationship type starts with a...
Our first graph
‣ Navigate to http://localhost:7474
‣ Type the following into the pane at the top:
:play http://guides.neo...
Follow Along
Run the first guide with us
When there are slides to see
Continue
Continue with the Guide
Take Note
Constraints
Unique constraints
We create unique constraints to:
‣ ensure uniqueness
‣ allow fast lookup of nodes which match
these (la...
Unique constraints
We create unique constraints to:
‣ ensure uniqueness
‣ allow fast lookup of nodes which match
these (la...
Continue
Continue with the Guide
End of Section 1
Continue with the Guide
Follow Along
Run the next guide with us
Take Note
Deleting
Deleting data
The DELETE command allows us to delete nodes
and relationships...but we can’t delete nodes if
they still hav...
Deleting data
The DELETE command allows us to delete nodes
and relationships...but we can’t delete nodes if
they still hav...
Deleting data
The DETACH DELETE command is our friend
when we want to delete a node and all
relationships attached to it.
...
Deleting schema
We can delete constraints as well by changing
‘CREATE’ to ‘DROP’ in the command
CREATE CONSTRAINT ON (c:Ch...
Follow Along
Continue with the guide
Take Note
LOAD CSV
LOAD CSV
‣ Import data from a HTTP or file URI
• LOAD CSV WITH HEADERS FROM "file://" AS row
LOAD CSV WITH HEADERS FROM "h...
Continue
Continue with the Guide
Take Note
Aggregation queries
Aggregation queries
We don’t specify a GROUP BY key when using
aggregation functions. The key is all non
aggregation field...
Aggregation queries
We don’t specify a GROUP BY key when using
aggregation functions. The key is all non
aggregation field...
Follow Along
Continue with the guide
End of Section 2
Let’s take a 5 minute break
Follow Along
Onto the next guide
Take Note
Advanced aggregation queries
Let’s talk about joins
Houses Episodes
Characters
Houses Episodes
Characters
Let’s talk about joins
We can use the WITH clause to work around this
problem
WITH
The WITH clause allows query parts to be chained
together, piping the results from one to be used
as starting points ...
WITH
It’s used to:
‣ limit the number of entries that are then
passed on to other MATCH clauses.
‣ filter on aggregated va...
WITH
MATCH (h:House)<-[:HAS_ALLEGIANCE_TO]-(c:Character)-[:APPEARED_IN]->()
RETURN c.id, c.name, COLLECT(h.name) AS houses...
Follow Along
Continue with the guide
End of Section 3
One more to go
Tweet us your pictures
@neo4j
@WomenWhoCode
Thanks for coming!
That’s all for today!
Thanks for coming!
<3
Resources
HBO Game of Thrones
Wikipedia
Family Tree House Stark
Game of Thones Wikia
Cool Interactive Infographic
http://w...
Neo4j Introduction  - Game of Thrones
Neo4j Introduction  - Game of Thrones
Neo4j Introduction  - Game of Thrones
Prochain SlideShare
Chargement dans…5
×

Neo4j Introduction - Game of Thrones

1 241 vues

Publié le

Want to improve your Cypher skills? This is just the session for you! You don't need any experience of coding/programming. We will be writing queries using Neo4j's query language but we'll start from scratch and work from there through the session.

This 3 hour session will be a mixture of theory and hands-on practice sessions, and you will quickly learn how easy it is to work with a powerful graph database using Cypher as the query language.

We will use the well known Game Of Thrones book and TV series as dataset because it is fun and rich in relationships of many kinds. We will create, import and query the data to gain some new and surprising insights and confirm things we already know.

Publié dans : Données & analyses
  • Soyez le premier à commenter

Neo4j Introduction - Game of Thrones

  1. 1. Intro to Neo4j @praveenasekhar / @markneedham <3
  2. 2. Tweet us your pictures @neo4j @WomenWhoCode Welcome!
  3. 3. Logistics ‣ Wi-fi • network: LNVisitor • user/password: LNGuest / LNGuest ‣ Grab a USB key from one of the tables or download from neo4j.com/download ‣ Install Neo4j 3.0.3
  4. 4. They GoT the title wrong ... There maybe spoilers.. [Maybe]
  5. 5. Example
  6. 6. Game of Thrones Wiki
  7. 7. By the end you will help us work out ‣ Who is the most prominent character in a season? ‣ Which house features the most characters? ‣ How are Starks and Targaryens related?
  8. 8. A quick show of hands... How many people have used databases before?
  9. 9. A quick show of hands... How many people have used Neo4j before?
  10. 10. A quick show of hands... How many people have watched Game of Thrones?
  11. 11. Whiteboard / Post-It Exercise Everyone! List down different types of entities and relationships that tie them in the Game of Thrones universe! http://gameofthrones.wikia.com/wiki/Game_of_Thrones_Wiki
  12. 12. ‣ Actors ‣ Characters ‣ Allegiances ‣ Houses ‣ Episodes ‣ Locations What data do we have?
  13. 13. ‣ An introduction to Neo4j and the Cypher query language ‣ GoT characters and episodes ‣ GoT houses ‣ GoT family relationships Agenda
  14. 14. Example
  15. 15. A brief into to the graph data model
  16. 16. GoT graph model
  17. 17. Nodes
  18. 18. Labels
  19. 19. Properties
  20. 20. Relationships
  21. 21. Introducing Cypher
  22. 22. What is Cypher? ‣ The graph query language ‣ Declarative and based on finding patterns ‣ ASCII Art + Query Language = Cypher
  23. 23. Nodes () or (n) ● Surrounded with parentheses ● Use an alias to refer to our node later (n:Label) ● Specify a Label - grouping nodes by roles or types ● Think of Labels like "Tables"++ (n:Label {prop: 'value'}) ● Nodes can have properties
  24. 24. Relationships --> or -[:TYPE]-> ● Hyphenated & encased in square brackets ● Like labels, a relationship type starts with a colon : ● < > Specify the direction of the relationship -[:TYPE {propertyName: "value"}]-> ● Relationships can have properties too!
  25. 25. Our first graph ‣ Navigate to http://localhost:7474 ‣ Type the following into the pane at the top: :play http://guides.neo4j.com/got
  26. 26. Follow Along Run the first guide with us
  27. 27. When there are slides to see
  28. 28. Continue Continue with the Guide
  29. 29. Take Note Constraints
  30. 30. Unique constraints We create unique constraints to: ‣ ensure uniqueness ‣ allow fast lookup of nodes which match these (label,property) pairs.
  31. 31. Unique constraints We create unique constraints to: ‣ ensure uniqueness ‣ allow fast lookup of nodes which match these (label,property) pairs. CREATE CONSTRAINT ON (c:Character) ASSERT c.name IS UNIQUE
  32. 32. Continue Continue with the Guide
  33. 33. End of Section 1 Continue with the Guide
  34. 34. Follow Along Run the next guide with us
  35. 35. Take Note Deleting
  36. 36. Deleting data The DELETE command allows us to delete nodes and relationships...but we can’t delete nodes if they still have relationships
  37. 37. Deleting data The DELETE command allows us to delete nodes and relationships...but we can’t delete nodes if they still have relationships MATCH (n) DELETE n org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException: Cannot delete node<0>, because it still has relationships. To delete this node, you must first delete its relationships.
  38. 38. Deleting data The DETACH DELETE command is our friend when we want to delete a node and all relationships attached to it. MATCH (n) DETACH DELETE n
  39. 39. Deleting schema We can delete constraints as well by changing ‘CREATE’ to ‘DROP’ in the command CREATE CONSTRAINT ON (c:Character) ASSERT c.name IS UNIQUE; DROP CONSTRAINT ON (c:Character) ASSERT c.name IS UNIQUE;
  40. 40. Follow Along Continue with the guide
  41. 41. Take Note LOAD CSV
  42. 42. LOAD CSV ‣ Import data from a HTTP or file URI • LOAD CSV WITH HEADERS FROM "file://" AS row LOAD CSV WITH HEADERS FROM "http://" AS row ‣ Transform and convert CSV values • MATCH (node1:Label {property: row.propertyValue}) CREATE (node2:Label {property: row.propertyValue}) MERGE (node3:Label {property: row.propertyValue}) • CREATE (node1)-[:REL_TYPE]->(node2) MERGE (node1)-[:REL_TYPE]->(node2)
  43. 43. Continue Continue with the Guide
  44. 44. Take Note Aggregation queries
  45. 45. Aggregation queries We don’t specify a GROUP BY key when using aggregation functions. The key is all non aggregation fields in the RETURN statement.
  46. 46. Aggregation queries We don’t specify a GROUP BY key when using aggregation functions. The key is all non aggregation fields in the RETURN statement. MATCH (character:Character)-[:APPEARED_IN]->() RETURN character.name, COUNT(*) AS appearances ORDER BY appearances DESC
  47. 47. Follow Along Continue with the guide
  48. 48. End of Section 2 Let’s take a 5 minute break
  49. 49. Follow Along Onto the next guide
  50. 50. Take Note Advanced aggregation queries
  51. 51. Let’s talk about joins Houses Episodes Characters Houses Episodes Characters
  52. 52. Let’s talk about joins We can use the WITH clause to work around this problem
  53. 53. WITH The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next.
  54. 54. WITH It’s used to: ‣ limit the number of entries that are then passed on to other MATCH clauses. ‣ filter on aggregated values ‣ separate reading from updating of the graph
  55. 55. WITH MATCH (h:House)<-[:HAS_ALLEGIANCE_TO]-(c:Character)-[:APPEARED_IN]->() RETURN c.id, c.name, COLLECT(h.name) AS houses, COUNT(*) AS appearances ORDER BY appearances DESC MATCH (h:House)<-[:HAS_ALLEGIANCE_TO]-(c:Character) WITH c, COLLECT(h.name) as houses MATCH (c)-[:APPEARED_IN]->() RETURN c.id, c.name, houses, COUNT(*) AS appearances ORDER BY appearances DESC
  56. 56. Follow Along Continue with the guide
  57. 57. End of Section 3 One more to go
  58. 58. Tweet us your pictures @neo4j @WomenWhoCode Thanks for coming!
  59. 59. That’s all for today! Thanks for coming! <3
  60. 60. Resources HBO Game of Thrones Wikipedia Family Tree House Stark Game of Thones Wikia Cool Interactive Infographic http://www.fastcodesign.com/1671439/infographic-every- murder-in-game-of-thrones-in-just-90-seconds https://www.washingtonpost.com/graphics/entertainment/game- of-thrones/ http://winteriscoming.net/2016/04/18/infographic-shows-that- death-has-been-good-for-game-of-thrones-ratings/ 15 GoT Infographics http://hauteslides.com/2011/05/game-of-thrones-infographic- illustrated-guide-to-houses-and-character-relationships/ Social Media Infographics Betrayal Graph Impressive GoT Railroad Map Character Relationship Graph from Book 3 NLP Analytics

×