1
votes

I will try to be very succinct with my problem. I have the node Person that I loaded using a .csv file and I have another .csv file to be loaded - person_speaks_language_0.csv

(got this header: idPerson|languagePSL )

How can I relate this? How can I create this relationship?

Grabbing another example, that is very similar to the previous one, and that I can't solve. I have the Comment node loaded in Neo4j an I need to load another .csv file, that file is - comment_replyOf_comment_0.csv

(got his header: idComment|idComment)

How can I load this file? How can I connect a relation that goes "in and out" from the same node - that connects the same node?

1
Yes. I forgot to mention but I need to write the clauses in Cypher code.José Guia
Here's another StackOverflow question about self-referential nodes in Neo stackoverflow.com/questions/22185212/…Ray Toal
Humm let my try that approach. Thanks for the tip @RayToalJosé Guia

1 Answers

3
votes

For the first example. there is 2 options.

If you want Language to be a separate node, try this cypher:

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MATCH (p:Person) 
WHERE p.id=line[0]
MERGE (p)-[r:Speaks]->(l:Language { name: line[1])})
RETURN p, l, r

Or, probably, better option

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MERGE (p:Person { id:line[0] })-[r:Speaks]->(l:Language { name: line[1]) })
RETURN p, l, r

If you want Language to be a property, try this:

LOAD CSV FROM 'person_speaks_language_0.csv' AS line
MERGE (p { id:line[0], language:line[1] })
RETURN p

The RETURN statement is optional and you don't want to include it for a big csv files (although it could be useful for debug).

For the second example, try this:

LOAD CSV FROM 'comment_replyOf_comment_0.csv' AS line
MERGE (c1:Comment { id:line[0] })-[r:Commented]->(c2:Comment { id:line[1]) })
RETURN c1, r, c2