0
votes

A big csv file (ca. 7 GB), which is my result of some pairwise computation between rows of objects 1 and objects 2 using 3 different methods looks like this:

obj 1 , obj 2 , method1 , method2 , method3

obj1 & obj2 are strings and method1,method2,method3 are float values.

I don't want to import the whole csv into Neo4j, but when values of method1 is above certain threshold, I want that specific row be imported and between object1 and object2 of that row an edge to be defined and the same for method2 and method3, what I mean is, that when values of method2 is above certain threshold, I want that specific row be imported and between object1 and object2 of that row an edge to be defined. thanks @cybersam and @Dave Bennett, who wroted me here original queries, I changed them a bit and run 3 following queries seperately. After that when i write a for example simple query like:

   match (n)-[r:similar_on_method2]-(m) return n,r,m 

I get not only demanded relation but other relations included in result graph, I dont know, what is wrong ?!

 Using periodic commit
 LOAD CSV WITH HEADERS
 FROM 'file:///objects.csv'
 AS line
 WITH line
 WHERE toFloat(line.method1) >= $x
 MERGE (obj1:Object {name: line.obj1})
 MERGE (obj2:Object {name: line.obj2})
 MERGE (obj1)-[:similar_on_method1]->(obj2)


 Using periodic commit
 LOAD CSV WITH HEADERS
 FROM 'file:///objects.csv'
 AS line
 WITH line
 WHERE toFloat(line.method2) >= $x
 MERGE (obj1:Object {name: line.obj1})
 MERGE (obj2:Object {name: line.obj2})
 MERGE (obj1)-[:similar_on_method2]->(obj2)


 Using periodic commit
 LOAD CSV WITH HEADERS
 FROM 'file:///objects.csv'
 AS line
 WITH line
 WHERE toFloat(line.method3) >= $x
 MERGE (obj1:Object {name: line.obj1})
 MERGE (obj2:Object {name: line.obj2})
 MERGE (obj1)-[:similar_on_method3]->(obj2)
1

1 Answers

0
votes

I guess how big is big? But something along these lines should get you started. If the obj1 and obj2 values repeat in your data or already exist in your database, you will want to create some indexes on the obj1 and obj2 values.

LOAD CSV WITH HEADERS
FROM 'file:///objects.csv'
AS line
WITH line
WHERE toInteger(line.method1) >= $x
AND toInteger(line.method2) >= $y
AND toInteger(line.method3) >= $z
MERGE (obj1:Object {name: line.obj1})
MERGE (obj2:Object {name: line.obj2})
MERGE (obj1)-[:LINK]->(obj2)