cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Is it possibel to create a relationship based on data from a CSV file?

Exampel, CSV file with heders.
<
SourceComNetName;Relationship;TargetComNetName
Network A;is_part_of;Network B
Network C;is_composed_of;Network D
/>

Cypher:
<
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
FIELDTERMINATOR ';'
MERGE (sComNetwork:ComNetwork {name: line.SourceComNetName})
MERGE (tComNetwork:ComNetwork {name: line.TargetComNetName})
MERGE (sComNetwork)-[:line.Relationship]->(tComNetwork)
/>

The last line will generate an Error.
Error:
Invalid input '.': expected
"*"
"]"
"{"
"|"
"$" (line 5, column 27 (offset: 226))
"MERGE (sComNetwork)-[:line.Relationship]->(tComNetwork)"

Way don't line.Relationship get substituted with "is_part_of" and "is_composed_of"?
Is it possible to dynamicly use data from the CSV file to generate the folowing relationships?

(Network A)-[is_part_of]->(Network B)
(Network C)-[is_composed_of]->(Network D)

3 REPLIES 3

clem
Graph Steward

I think you can do:

MERGE (sComNetwork)-[:TEMPREL {RelationshipType: line.Relationship} ]->(tComNetwork)

and then later add the Relationship type based on the RelationshipType property, and then delete the TEMPREL label.

I don't know if there is a way to get Cypher to evaluation a value and make it the actual relationship.

ameyasoft
Graph Maven
Use APOC:
CALL apoc.create.relationship(sComNetwork, line.Relationship, {}, s) YIELD rel
REMOVE rel.noOp

REMOVE rel.noOp is dummy one as CALL statement must end with RETURN.



Tank you! This works OK for me.