Load Data for the Exercises

Load Data for the Exercises (Preparations)


Before you perform the exercises for this course, complete the following steps:

  1. Install Neo4j Desktop.

  2. Create a Project named Graph Algos.

  3. Create a local 4.1 database or Neo4j Sandbox.

  4. Install the APOC plugin for use with this database. (Only for local installation)

  5. Install the Graph Data Science plugin for use with this database. (Only for local installation)

  6. Install the Graph Data Science Playground Graph App. (Only for local installation)

  7. Start the database.

  8. Start the Graph Data Science Playground Graph App.

Go to the next page to load the data.

Step 1: Load the data from Graph Data Science Playground


In Graph Data Science Playground:

  1. Click the cog in the upper right part of the panel and select Sample Graphs.

  2. Click Select , followed by Yes, load it! to load these datasets:

    1. Game of Thrones

    2. European Roads

    3. Recipes

Do not load the Twitter dataset as it conflicts with the other datasets!

Step 2: Load some other data from Neo4j Browser


We will load some additional small graphs to demonstrate graph algorithms. In Neo4j Browser, execute this code:

MERGE (nAlice:Person {name:'Alice'})
MERGE (nBridget:Person {name:'Bridget'})
MERGE (nCharles:Person {name:'Charles'})
MERGE (nDoug:Person {name:'Doug'})
MERGE (nMark:Person {name:'Mark'})
MERGE (nMichael:Person {name:'Michael'})
MERGE (nAlice)-[:HELPS{weight:5.0}]->(nBridget)
MERGE (nAlice)-[:HELPS{weight:1.5}]->(nCharles)
MERGE (nMark)-[:HELPS{weight:2.0}]->(nDoug)
MERGE (nMark)-[:HELPS{weight:1.7}]->(nMichael)
MERGE (nBridget)-[:HELPS{weight:0.5}]->(nMichael)
MERGE (nDoug)-[:HELPS{weight:1.1}]->(nMark)
MERGE (nMichael)-[:HELPS{weight:0.5}]->(nAlice)
MERGE (nAlice)-[:HELPS{weight:1.1}]->(nMichael)
MERGE (nBridget)-[:HELPS{weight:2.6}]->(nAlice)
MERGE (nMichael)-[:HELPS{weight:1.8}]->(nBridget)

Then execute this code:

MERGE (neo4j:Tag {name:'neo4j'})
MERGE (graphql:Tag {name:'graphql'})
MERGE (cypher:Tag {name:'cypher'})
MERGE (graph:Tag {name:'graph'})
MERGE (python:Tag {name:'python'})
MERGE (html:Tag {name:'html'})
MERGE (css:Tag {name:'css'})
MERGE (js:Tag {name:'javascript'})

MERGE (query:Question {name: "How can I optimize this query in neo4j?"})
MERGE (path:Question {name: "Neo4j finding a path between two stations"})
MERGE (grand:Question {name: "How to write relationship mutation in GraphQL using GRANDstack?"})
MERGE (pythonq:Question {name: "Quicker way to write a dict to a neo4j database using python"})
MERGE (list:Question {name: "How to make a responsive horizontal list"})
MERGE (box:Question {name: "3D box tilt with JavaScript and css"})

MERGE (query)-[:HAS_TAG]->(graph)
MERGE (query)-[:HAS_TAG]->(neo4j)
MERGE (query)-[:HAS_TAG]->(cypher)

MERGE (path)-[:HAS_TAG]->(neo4j)
MERGE (path)-[:HAS_TAG]->(cypher)
MERGE (path)-[:HAS_TAG]->(graph)

MERGE (grand)-[:HAS_TAG]->(neo4j)
MERGE (grand)-[:HAS_TAG]->(graphql)

MERGE (pythonq)-[:HAS_TAG]->(neo4j)
MERGE (pythonq)-[:HAS_TAG]->(python)
MERGE (pythonq)-[:HAS_TAG]->(cypher)

MERGE (list)-[:HAS_TAG]->(html)
MERGE (list)-[:HAS_TAG]->(css)

MERGE (box)-[:HAS_TAG]->(html)
MERGE (box)-[:HAS_TAG]->(css)
MERGE (box)-[:HAS_TAG]->(js)

Step 3: Calculate inverse value of distance


The European Roads network is a weighted graph, where the distance between places in kilometers is stored as a relationship weight. In this course, we will examine the community structure and centrality of the European Roads network. Community Detection and Centrality algorithms deduce that a higher relationship weight represents a stronger relationship. In our case, the greater the relationship weight is, the weaker the relationship strength is as the cities are farther away. For this reason, we will calculate the inverse value of the distance, which will be used as an input relationship weight in Community Detection and Centrality algorithms.

In Neo4j Browser, execute this code:

MATCH (:Place)-[r:EROAD]->(:Place)
SET r.inverse_distance = 1.0 / log10(r.distance + 2)

Step 4: Verify data has been loaded.


After you have loaded the data, open a Neo4j Browser window to the started database and view the database information.

DataLoaded

Refresh the database contents in NEuler to have the new datasets available for algorithm execution.

The database contents in NEuler will look as follows:

LoadedNEuler

Load Data for the Exercises (Summary)


Your database is now set up and ready for you to gain experience with graph algorithms.