我正在从几个csv文件中迭代地上传节点和边缘,每个节点类型一个。加载节点运行良好,但加载边缘并不总是有效。实际上,一些节点将数字作为标识符 - 如果是这样,那个类型的所有节点都有数字 - 但是作为字符串加载,因此创建边缘失败。手动创建边缘添加用双引号包装标识符效果很好。
如何在创建节点时强制LOAD CSV为这些标识符使用数字,或强制LOAD CSV用双引号包装标识符?
文章节点:
Type PMID ArticleTitle AbstractText Date Pages
Article 25358116 Synthesis of... Abstract 2014-10-30
Article 25358093 Putting theory... In this study... 2014-10-30 e1003910
问题节点:
Type Name Year Month Volume Issue
Issue J. Med. Chem., 2014 2014 Oct
Issue PLoS Comput. Biol., 2014, 10, 10 2014 Oct 10 10
Issue PLoS ONE, 2014, 9, 10 2014 9 10
边缘:
Name PMID
J. Med. Chem., 2014 25358116
PLoS Comput. Biol., 2014, 10, 10 25358093
Cypher命令:
CREATE INDEX ON :Article(PMID);
LOAD CSV WITH HEADERS FROM 'article.nodes' as csvLine FIELDTERMINATOR '\t' CREATE (:Article { PMID: toInt(csvLine.PMID), Title: csvLine.ArticleTitle, Date: csvLine.Date, Pages: csvLine.Pages, AbstractText: csvLine.Abstract }) return count(*);
CREATE INDEX ON :Journal(Abbreviate);
CREATE INDEX ON :Issue(Name);
LOAD CSV WITH HEADERS FROM 'issue.nodes' as csvLine FIELDTERMINATOR '\t' CREATE (:Issue { Name: csvLine.Name, Volume: csvLine.Volume, Issue: csvLine.Issue, Year: csvLine.Year, Month: csvLine.Month}) return count(*);
LOAD CSV WITH HEADERS FROM 'article.edges' as csvLine FIELDTERMINATOR '\t' MATCH (src:Issue { Name: csvLine.Name }), (tgt:Article { PMID: toInt(csvLine.PMID) }) CREATE (src) -[:hasArticle]-> (tgt) return count(*);
答案 0 :(得分:1)
您可以使用toInt(csvline.id)例如:
http://neo4j.com/docs/stable/query-functions-scalar.html#functions-toint
答案 1 :(得分:1)
收到文件后,TSV出现格式化问题。
在neo4j中显示整个csvLine显示我的问题名称为null,因此我修改了格式并使用google驱动器重新导出文件。
您也可以检查CsvLINT http://csvlint.io/validation/545681456373761303020000
上的错误LOAD CSV WITH HEADERS FROM 'file:///Users/ikwattro/dev/playbox/pierre/article.edges' as csvLine FIELDTERMINATOR '\t' WITH csvLine LIMIT 10 RETURN csvLine
I get this
Name PMID J. Med. Chem., 2014 25358116
Name PMID PLoS Comput. Biol., 2014, 10, 10
Name PMID J. Med. Chem., 2014
Name PMID J. Med. Chem., 2014
Name And PMID Are under the same key
克里斯