Neo4j Cypher-使用两个CSV文件创建关系 [英] Neo4j Cypher - Creating relationship using two CSV files
问题描述
我是Neo4j的新手,目前正在构建引文网络.
I'm new to Neo4j and I'm currently working on to build a citation network.
我有两个CSV文件,一个包含节点属性,另一个包含关系属性.
I have two CSV files one containing the node properties and other containing relationship properties.
PAPERS.CSV-
PAPERS.CSV -
paperId, title, year
123, abc, 1900
234, cde, 1902
456, efg, 1904
CITES.CSV-
CITES.CSV -
fromId, ToId
123, 234
234, 456
我的图形应类似于(123)--cites-->(234)--cites-->(456)
.
使用这些文件,如何在节点之间建立关系?
My graph should look like (123)--cites-->(234)--cites-->(456)
.
Using these files how do I create a relationship between nodes?
推荐答案
您还应避免标题名称和数据中的空格. 如果超出您的控制范围,则可以使用修剪功能和反引号来引用标头名.但是通常,您的csv应该是干净的. 您的文件应位于neo4j的import目录中.否则,您应该注释掉neo4j.conf中的dbms.directories.import = import属性.
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. Your files should be in the import directory of the neo4j. Otherwise you should comment out dbms.directories.import=import property in neo4j.conf.
您可以这样创建节点:
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`)});
您可以创建如下关系:
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);
这篇关于Neo4j Cypher-使用两个CSV文件创建关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!