Skip to main content

Neo4j Corona Tracing

Shenzhen, China

Installing Neo4j Desktop

Download the latest version of the Neo4j Desktop AppImage and make it executable:

chmod a+x neo4j-desktop-offline-1.2.9-x86_64.AppImage

Then run it from your Terminal ./neo4j-desktop-offline-1.2.9-x86_64.AppImage.

Creating your Database

  1. Click on New Project, create the database and click on Manage to set it up.

Neo4j Desktop Application

  1. Click on Open Folder, enter the import directory.

  2. Copy your Corona Tracing Data as .csv file into the directory.

Neo4j Desktop Application

Alternative: If you are running Neo4j inside a Docker Container copy this file to /opt/neo4j/import and use the web client to run the import.

Neo4j Desktop Application

  1. Now start the database and open the Neo4j Explorer.

Neo4j Desktop Application

Importing Data

Run the following Cypher query to add your data to your database:

LOAD CSV WITH HEADERS FROM 'file:///coronaTracing.csv' AS line
WITH line
MERGE (Infected:Person{name:line.Infected, Addr:line.InfectedAddress})
MERGE (Contact:Person{name:line.Contact, Addr:line.ContactAddress})
MERGE (Infected)-[info:Info{
`Contact Info`:line.ContactInfo,
`Relationship`:line.`Relationship`,
Location: CASE WHEN line.Geography IS NOT NULL THEN line.Geography ELSE '' END
}]->(Contact)

Neo4j Desktop Application

Working with your Data

  1. How many potential infections (query for relationship Info = event with the potential of an infection) ?
MATCH (person:Person)-[rel:Info]->(:Person)
RETURN COUNT (rel)
  1. How many persons have been traced from Cordon M ?
MATCH (person:Person)
WHERE person.Addr = 'CordonM'
RETURN person
  1. How many infected persons has Person A been in contact with ?
MATCH (carrier)-[r:Info]->(person:Person{name:'PersonA'})
RETURN carrier, person, r
  1. How many were potentially infected by Person J ?
MATCH (carrier:Person{name:'PersonJ'})-[r:Info]->(person:Person)
RETURN COUNT (person) AS Infected

4.1. Omit potential double-count:

MATCH (carrier:Person{name:'PersonJ'})-[r:Info]->(person:Person)
RETURN COUNT (DISTINCT person) AS Infected
  1. Select all and order by number of potential infection event - find Super Spreader:
MATCH (carrier:Person)-[rel:Info]->(person:Person)
RETURN carrier, COUNT(carrier) AS Infected
ORDER BY Infected DESC
LIMIT 10

Switch results from Graph to Table to see the persons who are most likely to be super spreader

  1. Select list of persons with highest number of potential infections:
MATCH (n)-[r:Info]->(m)
WITH n, COUNT((n)-[]->()) as num
ORDER BY num DESC
LIMIT 10
MATCH (n)-[i]->(b)
RETURN n,i,b
  1. Show the person that exposed the most:
MATCH (carrier:Person)-[rel:Info]->(person:Person)
RETURN person, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 1
  1. What carriers had contact with the person who was exposed the most ?
MATCH (carrier:Person)-[rel:Info]->(person:Person)
WITH person, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 1
MATCH (person:Person)<-[r]-(p)
RETURN person, r, p
  1. Who in Cordon A did not infect anyone ?
MATCH (a)
WHERE NOT(a:Person)-[:Info]->()
AND a.Addr = 'CordonA'
RETURN a
  1. Select carrier that infected the most of their own cordon:
MATCH (carrier:Person)-[r]->(person:Person)
WHERE carrier.Addr = person.Addr
WITH carrier, COUNT(*) AS Infections
ORDER BY Infections DESC
LIMIT 2
MATCH (p:Person)<-[r]-(carrier)
RETURN p,r,carrier
  1. Show the path of the infection between Person K and Person L
MATCH path=(p1:Person{name:'PersonK'})-[*]->(p2:Person{name:'PersonL'})
RETURN path