Skip to content

Instantly share code, notes, and snippets.

@Taresin
Last active February 2, 2025 10:20
Show Gist options
  • Save Taresin/480912754bb82b4a7491bfafe95bea8a to your computer and use it in GitHub Desktop.
Save Taresin/480912754bb82b4a7491bfafe95bea8a to your computer and use it in GitHub Desktop.
Fetching and processing CSV data of the character relationships of Harry Potter
// Basic import from a CSV file hosted online
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/efekarakus/potter-network/master/data/characters.csv' AS character
CREATE (c:Character {
id: character.id,
name: character.name,
bio: character.bio
});
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/efekarakus/potter-network/master/data/relations.csv' AS relationship
MATCH (a:Character {id: relationship.source})
MATCH (b:Character {id: relationship.target})
WHERE relationship.type = '-'
MERGE (a)-[:NEGATIVE_REL]->(b);
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/efekarakus/potter-network/master/data/relations.csv' AS relationship
MATCH (a:Character {id: relationship.source})
MATCH (b:Character {id: relationship.target})
WHERE relationship.type = '+'
MERGE (a)-[:POSITIVE_REL]->(b);
// Find the most popular character among the characters in the dataset
MATCH (c:Character)
MATCH (c)<-[r:POSITIVE_REL]-()
RETURN c.name, count(r) AS popularity
ORDER BY popularity DESC
// Find which character has the most negative relationships
MATCH (c:Character)
MATCH (c)<-[r:NEGATIVE_REL]-()
RETURN c.name, count(r) AS negativity
ORDER BY negativity DESC
// Find circles of characters that have positive relationships with each other
MATCH (a:Character)-[:POSITIVE_REL]->(b:Character)-[:POSITIVE_REL]->(c:Character)-[:POSITIVE_REL]->(a)
RETURN a, b, c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment