PetyrBaelish
PetyrBaelish

Reputation: 39

neo4j - creating graph projection from flat data

I'm brand new to Neo4j, and I'm having difficulty relating the guidance docs to my data to crate some graph projections...

I've loaded data into a table: LOAD CSV WITH HEADERS FROM 'https://***.csv' AS row MERGE (Category{user1: row.User1, user2: row.User2, Count: row.Count})

An example of the data is:

enter image description here

I'm trying to create a graph projection on the basis the 'Row: user1' -> has_followed -> 'Row: user2' (the no. of times specified in count) but haven't quite got the syntax right.

I intend to create a graph projection per category.

EDIT - here's an example of my expected output with all the sample data provided (which in practice I would do as 2 separate graphs based on the "category"): enter image description here

Upvotes: 1

Views: 95

Answers (1)

jose_bacoy
jose_bacoy

Reputation: 12704

User1 and User2 belongs to the same class (node): Person The relationship between person is :has_followed with counts and category as attributes. Here is the script to load the data such as

LOAD CSV WITH HEADERS FROM 'https://***.csv' AS row
MERGE (p1: Person {name: row.User1})
MERGE (p2: Person {name: row.User2})
MERGE (p1)-[:HAS_FOLLOWED {count: row.Count, category: row.Category}]-> (p2)

No need to worry about Tim, Harry and Danny because this person is found in multiple rows. Merge command will not create another node (Person) if it already exists.

Upvotes: 0

Related Questions