neo4j双UNWIND拆分

时间:2014-07-26 15:50:57

标签: csv neo4j load


我有以下.csv文件

day,month,year,mps,party,subjectofquest,typeofquest,period,ministry<br/>
"1","1","2012","mp1,mp2,mp3","party1","subject1","type1","1","ministry1,ministry2"

我试图在Mark Needhams指导(http://java.dzone.com/articles/neo4j-load-csv-processing)之后拆分mps和部门细胞 它们中的每一个都可以作为独立命令完成,但我无法确定如何对其进行编译(经过这么多努力......)
执行mp单元作业的代码如下:

load csv with headers from " file:///test/MESA2.csv " AS row<br/>  
  WITH row, split(row.mps, ",") AS mps<br/>  
  UNWIND mps AS mpname  <br/> 
  MERGE (p1:Question {questsub:row.subjectofquest})<br/>
  MERGE (p2:MP {mpname: mpname})<br/>
  MERGE (p3:Ministry{questministry: row.ministry})<br/>
  MERGE (p2)-[:ASKS_MKE]->(p1)<-[:REFERS]-(p3);<br/>

我为双UNWIND尝试了几种语法,这是其中之一,但没有人工作:

load csv with headers from " file:///test/MESA2.csv " AS row <br/> 
  WITH row, split(row.mps, ",") AS mps <br/> 
  UNWIND mps AS mpname  <br/> 
  MERGE (p1:Question {questsub:row.subjectofquest})<br/>
  MERGE (p2:MP {mpname: mpname})<br/>
  MERGE (p2)-[:ASKS_MKE]->(p1)<br/>
  WITH row, split(row.ministry, ",") AS ypourgeio <br/> 
  UNWIND ypourgeio AS ypourgeio1<br/>
  MERGE (p3:Ypname{ypourgeio: ypourgeio}) <br/>
  MERGE (p1)-[:REFERS]->(p3)<br/>

请帮助(我想我可以通过VB拆分excel,但它会很糟糕!)
提前谢谢!
Nektarios

1 个答案:

答案 0 :(得分:1)

Nektarios,

我不确定你是否在mps和部门中都有可变数量的子字段,但假设你这样做,而你想要全部匹配,请尝试这样做:

LOAD csv WITH HEADERS FROM " file:///test/MESA2.csv " AS row
WITH row, SPLIT(row.mps, ",") AS mps, SPLIT(row.ministry, ",") as ministries
UNWIND mps AS mpname
WITH row, mpname, ministries
UNWIND ministries AS ministry
MERGE (p1:Question {questsub:row.subjectofquest})
MERGE (p2:MP {mpname: mpname})
MERGE (p3:Ministry{questministry: ministry})
MERGE (p2)-[:ASKS_MKE]->(p1)<-[:REFERS]-(p3);

我无法访问数据库进行尝试,因此我可能没有这样做。

恩典与和平,

吉姆