1
votes

I have a CSV file, which have 11 columns : Rank, Year, Name... It contains the best video games sales. I'm new to neo4j and cypher.

I am trying to import it to neo4j with this cypher query : LOAD CSV WITH HEADERS FROM 'file:///vgsales.csv' AS line CREATE (:Vgsales {rank: toInteger(line.Rank), name: line.Name, platform: line.Platform, year: toInteger(line.Year), genre: line.Genre, publisher: line.Publisher, NA_sales: toInteger(line.NA_Sales), EU_sales: toInteger(line.EU_Sales)], JP_sales: toInteger(line.JP_Sales), Other_sales: toInteger(line.Other_Sales), Global_sales: toInteger(line.Global_Sales)})

When i do this, I have the nodes, but there is no reationships between them, and I need to give the graph model with this query : call db.schema.visualization but there is only one empty node when I do this.

I don't understand why there isn't any relationships .

3

3 Answers

1
votes

Thanks for your answer. I'm posting back the query because there was an ']' that i forgot to remove :

LOAD CSV WITH HEADERS FROM 'file:///vgsales.csv' AS line CREATE(v:Vgsales {rank: toInteger(line.Rank), name: line.Name, platform: line.Platform, year:toInteger(line.Year)}) WITH v MERGE (g:GENRE {genre: line.Genre}) MERGE (p:PUBLISHER {publisher: line.Publisher, NA_sales: toInteger(line.NA_Sales), EU_sales: toInteger(line.EU_Sales), JP_sales: toInteger(line.JP_Sales), Other_sales: toInteger(line.Other_Sales), Global_sales: toInteger(line.Global_Sales)}) MERGE (v)-[:IN_GENRE]->(g) MERGE (p)-[:PUBLISHED]->(v) 

However the query still doesn't work. I have this error : enter image description here

This is how my dataset looks like : enter image description here

The exercise that I must do for tomorrow is to find a dataset, to find a problematic and to answer it with a plugin algorithm and then get the graph model and load the csv file in neo4j but i don't know how should add the relationships between the nodes.

1
votes

There is a syntax error on your script. You can remove this line below:

WITH v 

I tried it on my neo4j browser and it works well:

LOAD CSV WITH HEADERS FROM 'file:///vgsales.csv' AS line 
CREATE(v:Vgsales {rank: toInteger(line.Rank), name: line.Name, platform: line.Platform, year:toInteger(line.Year)}) 
//WITH v  <- remove this!
MERGE (g:GENRE {genre: line.Genre}) 
MERGE (p:PUBLISHER {publisher: line.Publisher, NA_sales: toInteger(line.NA_Sales), 
EU_sales: toInteger(line.EU_Sales), JP_sales: toInteger(line.JP_Sales), Other_sales: toInteger(line.Other_Sales), Global_sales: toInteger(line.Global_Sales)}) 
MERGE (v)-[:IN_GENRE]->(g) 
MERGE (p)-[:PUBLISHED]->(v) 

Result: Added 3 labels, created 3 nodes, set 11 properties, created 2 relationships, completed after 235 ms.
0
votes

From your code it seems like you have not created any relationship just a single node for each row in your csv. My suggesion is try to create a model first. you can use arrows.app to try and describe your model.

Relationships are created by joining two nodes lets say

CREATE (:PERSON {name:"CHARLIE")-[:FOLLOWS]->(:PERSON {name:"JOHN"})

And from your code id probably try something like

LOAD CSV WITH HEADERS FROM 'file:///vgsales.csv' AS line CREATE(v:Vgsales {rank: toInteger(line.Rank), name: line.Name, platform: line.Platform, year: toInteger(line.Year)}) WITH v MERGE (g:GENRE {genre: line.Genre}) MERGE (p:PUBLISHER {publisher: line.Publisher, NA_sales: toInteger(line.NA_Sales), EU_sales: toInteger(line.EU_Sales)], JP_sales: toInteger(line.JP_Sales), Other_sales: toInteger(line.Other_Sales), Global_sales: toInteger(line.Global_Sales)}) MERGE (v)-[:IN_GENRE]->(g) MERGE (p)-[:PUBLISHED]->(v)

I'm not sure that fits your model though you could try and draw your model and perhaps i will write a better code.