简体   繁体   English

Neo4j Cypher-使用两个CSV文件创建关系

[英]Neo4j Cypher - Creating relationship using two CSV files

I'm new to Neo4j and I'm currently working on to build a citation network. 我是Neo4j的新手,目前正在构建引文网络。

I have two CSV files one containing the node properties and other containing relationship properties. 我有两个CSV文件,一个包含节点属性,另一个包含关系属性。

PAPERS.CSV - CSV文件-

paperId, title, year
123, abc, 1900
234, cde, 1902
456, efg, 1904

CITES.CSV - CITES.CSV-

fromId, ToId
123, 234
234, 456

My graph should look like (123)--cites-->(234)--cites-->(456) . 我的图应该看起来像(123)--cites-->(234)--cites-->(456) Using these files how do I create a relationship between nodes? 使用这些文件,如何在节点之间建立关系?

You should avoid space in the header names and in the data too. 您应该在标题名称和数据中也避免空格。 If it is out of your control then you can use trim function and backticks to reference a headername. 如果超出您的控制范围,则可以使用修剪功能和反引号来引用标头名。 But normally, your csv should be clean. 但是通常,您的csv应该是干净的。 Your files should be in the import directory of the neo4j. 您的文件应位于neo4j的import目录中。 Otherwise you should comment out dbms.directories.import=import property in neo4j.conf. 否则,您应该注释掉neo4j.conf中的dbms.directories.import = import属性。

You can create nodes like this: 您可以这样创建节点:

   LOAD CSV WITH HEADERS FROM "file:///PAPERS.CSV" as line
   CREATE (p:Paper {paperId:trim(line.paperId), title: trim(line.` title`), year: trim(line.` year`)});

And you can create relationships like this: 您可以创建如下关系:

   LOAD CSV WITH HEADERS FROM "file:///CITES.CSV" as line
   MATCH (p1:Paper {paperId:trim(line.fromId)})
   MATCH (p2:Paper {paperId:trim(line.` ToId`)})
   CREATE (p1)-[:CITES]->(p2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM