2016-07-29 71 views
1

輸入數據暗號輸出

MATCH (n) DETACH DELETE n; 
CREATE (p:Provider {id:1, specialty:"Cardiology",  pcp:0}); 
CREATE (p:Provider {id:2, specialty:"Internal Medicine", pcp:1}); 
CREATE (p:Provider {id:3, specialty:"Family Practice", pcp:1}); 
CREATE (p:Provider {id:4, specialty:"Radiology",   pcp:0}); 

MATCH (p1:Provider {id:1}), (p2:Provider {id:2}) CREATE 
     (p1)-[:SHARED {mbrid:1}]->(p2), 
     (p1)-[:SHARED {mbrid:2}]->(p2), 
     (p1)-[:SHARED {mbrid:2}]->(p2), 
     (p1)-[:SHARED {mbrid:3}]->(p2); 
MATCH (p1:Provider {id:2}), (p2:Provider {id:3}) CREATE 
     (p1)-[:SHARED {mbrid:4}]->(p2), 
     (p1)-[:SHARED {mbrid:5}]->(p2); 
MATCH (p1:Provider {id:1}), (p2:Provider {id:3}) CREATE 
     (p1)-[:SHARED {mbrid:6}]->(p2); 
MATCH (p1:Provider {id:1}), (p2:Provider {id:4}) CREATE 
     (p1)-[:SHARED {mbrid:9}]->(p2), 
     (p1)-[:SHARED {mbrid:10}]->(p2), 
     (p1)-[:SHARED {mbrid:11}]->(p2), 
     (p1)-[:SHARED {mbrid:12}]->(p2), 
     (p1)-[:SHARED {mbrid:12}]->(p2); 

CREATE INDEX ON :Provider(id);   

查詢

MATCH (p1:Provider)-[s:SHARED]-(p2:Provider) 
WHERE p1.id<p2.id and (p1.pcp=0 or (p1.pcp=1 and p2.pcp=0)) 
WITH p1, p2, count(distinct s.mbrid) as cnt 
WHERE cnt>1 
RETURN p1, p2, cnt; 

輸出

+------------------------------------------------------------------------------------------------------+ 
| p1           | p2            | cnt | 
+------------------------------------------------------------------------------------------------------+ 
| Node[0]{id:1,specialty:"Cardiology",pcp:0} | Node[1]{pcp:1,id:2,specialty:"Internal Medicine"} | 3 | 
| Node[0]{id:1,specialty:"Cardiology",pcp:0} | Node[3]{id:4,specialty:"Radiology",pcp:0}   | 4 | 
+------------------------------------------------------------------------------------------------------+ 

我需要的輸出是在下面的格式。請注意,標識爲3的節點不在下面列出,因爲它不在輸出中。此外,輸出節點索引0,1,2和鏈接使用

{ 
    "nodes" : [ 
     { 
      "specialty" : "Cardiology", 
      "pcp" : 0 
     }, 
     { 
      "specialty" : "Internal Medicine", 
      "pcp" : 1 
     }, 
     { 
      "specialty" : "Radiology", 
      "pcp" : 0 
     } 
    ], 
    "links" : [ 
     { 
      "source" : 0, 
      "target" : 1, 
      "value" : 3 
     }, 
     { 
      "source" : 0, 
      "target" : 2, 
      "value" : 4 
     } 
    ] 
} 

我將不勝感激任何輸入/指示如何創建此。

回答

0

優化您的查詢以僅輸出您需要的節點,然後在Neo瀏覽器中單擊「導出到文件」按鈕(剛剛輸入的查詢文本旁邊)。然後選擇導出JSON