1
votes

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

1
can you draw the resulting graph that you expect?jose_bacoy
Thanks @âńōŋŷXmoůŜ - I've edited my post to include the intended output. As explained above, I'm struggling to follow the available guidance as it's generally on the basis of relational data - my data is in one file, and as identified by the diagram I need to represent User1 following User2 from both the same node, and the same "person" may appear as User1 in one node but User2 in a different node (for example Danny -> Harry & Harry -> Jack).PetyrBaelish

1 Answers

0
votes

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.