1

Suppose I have a csv file with data in the format (Subject, relation, Object).

Is it possible to load this into neo4j as a graph modeled such that the subject and object become nodes and the relation between them is the relation from the triple? Essentially while loading from the csv, I want to load the subject and object as individual nodes and the relation is the one joining them.

(subject)-[:relation]->(object)

My csv is in the format ent1,state,ent2 a,is,b . . .

cybersam
  • 63,203
  • 6
  • 53
  • 76
Abhinav23
  • 71
  • 9
  • Possible duplicate of [Neo4j load CSV to create dynamic relationship types](https://stackoverflow.com/questions/47808421/neo4j-load-csv-to-create-dynamic-relationship-types) – Rajendra Kadam Jun 08 '19 at 05:56

1 Answers1

2

Yes, It's possible. You need to install the APOC plugin in Neo4j and then use apoc.merge.relationship.

Refer the following query to load the data: Add/Modify required details in the query.

LOAD CSV FROM "file:///path-to-file" AS line
MERGE (sub:Subject {name:line[0]})
MERGE (obj:Object {name:line[2]})
WITH sub, obj, line
CALL apoc.merge.relationship(sub,line[1],{},{},obj) YIELD rel
RETURN COUNT(*);
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
  • I get this error when I ran this " Neo.ClientError.Statement.SyntaxError: Variable `line` not defined (line 6, column 34 (offset: 171)) "CALL apoc.merge.relationship(sub,line[1],{},{},obj) YIELD rel" ^". Keep getting the same variable not defined error every time – Abhinav23 Apr 24 '19 at 09:42
  • Can you share your query here? – Rajendra Kadam Apr 24 '19 at 09:45