在neo4j

时间:2017-12-05 12:11:32

标签: neo4j linked-list cypher

如图所示

Data model

是否可以在所有(:B)节点之间创建链接列表关系,该节点与[:R]节点共享关系(:A),对于所有(:A)节点数据库。如果顺序很重要,那么假设所有order个节点都有一个属性(:B)

3 个答案:

答案 0 :(得分:1)

我假设您在每个y2 <- c(0,0,NA,0,0,0,0); y <- c(0,0,0,NA,NA,0); x <- c(0,0,0,0) li <-list(y2 = y2,y = y,x = x) ## This is your example, where x is subset of both y and y2 uniquePath(li) # [[1]] # [1] 0 0 NA 0 0 0 0 # # [[2]] # [1] 0 0 0 NA NA 0 x <- c(0,0,0,0); y <- c(0,NA,0,0,0); y2 <- c(NA,NA,0,0,0,0) l <- list(x,y,y2) ## Here x is a subset of y and y is a subset of y2 uniquePath(l) # [[1]] # [1] NA NA 0 0 0 0 节点中都有order属性。我正在使用此示例数据:

:B

然后您可以使用此Cypher查询:

CREATE (a1:A)-[:R]->(:B {order : 1}), (a1)-[:R]->(:B {order : 2}), (a1)-[:R]->(:B {order : 3})
CREATE (a2:A)-[:R]->(:B {order : 1}), (a2)-[:R]->(:B {order : 2}), (a2)-[:R]->(:B {order : 3})

输出将是:

enter image description here

答案 1 :(得分:1)

另外一个选项:使用APOC Procedures。过程apoc.nodes.link()接收节点集合,并使用指定的关系类型将它们转换为链接列表。用法示例:

MATCH (A:A)-[:R]->(B:B)
WITH A, B 
ORDER BY B.order ASC
WITH A, collect(B) as bNodes
CALL apoc.nodes.link(bNodes, 'NEXT')

答案 2 :(得分:0)

dataframe