cancel
Showing results for 
Search instead for 
Did you mean: 

Building relationship among a list of codes

praveen049
Node

Hi
I have a dataset consisting of two csv files.

The first csv is a list of codes and their description. Example:
1, A
2, B
3, C

The second CSV, contains a list of related codes. Example
1, 2
1, 1
2, 3

The code may be related to themselves or to other codes. Some of the codes may not have any relations.

I have loaded the first csv and created nodes for the code and description
How can I load the second csv to create the relationships between the nodes ?

Thanks

Br
Praveen

1 ACCEPTED SOLUTION

praveen049
Node

I am able to get the relationship with the below queries:
LOAD CSV from 'file:///AllCodes.csv' as row
FIELDTERMINATOR ';'
with toInteger(row[0]) as codeID, row[1] as CodeDescription
MERGE (m:CodeList {codeID: codeID, CodeDescription: CodeDescription});

LOAD CSV from 'file:///CodeRelations.csv' as row
FIELDTERMINATOR ';'
with toInteger(row[0]) as leftID, toInteger(row[2]) as rightID
MATCH (code1), (code2)
WHERE code1.codeID = leftID AND code2.codeID = rightID
CREATE (code1)-[:PT]->(code2);

If there is any better/faster way to do it. Please do let me know.

Thanks

View solution in original post

1 REPLY 1

praveen049
Node

I am able to get the relationship with the below queries:
LOAD CSV from 'file:///AllCodes.csv' as row
FIELDTERMINATOR ';'
with toInteger(row[0]) as codeID, row[1] as CodeDescription
MERGE (m:CodeList {codeID: codeID, CodeDescription: CodeDescription});

LOAD CSV from 'file:///CodeRelations.csv' as row
FIELDTERMINATOR ';'
with toInteger(row[0]) as leftID, toInteger(row[2]) as rightID
MATCH (code1), (code2)
WHERE code1.codeID = leftID AND code2.codeID = rightID
CREATE (code1)-[:PT]->(code2);

If there is any better/faster way to do it. Please do let me know.

Thanks

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.