Neo4j;复杂密码查询

Neo4j;复杂密码查询,neo4j,cypher,Neo4j,Cypher,我有以下neo4j结构: :Label1 -[:rel-label-1]- :Label2 It may happen that :Label1 -- :Label3 And sometime :Label2 -[:rel-label-2]- :Label3 MATCH(n:Label1)--(:rel-label-1)--(z1:Label2) Followed by the 2 optional Matches to retrieve :Label3 and :rel-label-2 我

我有以下neo4j结构:

:Label1 -[:rel-label-1]- :Label2
It may happen that :Label1 -- :Label3
And sometime :Label2 -[:rel-label-2]- :Label3
MATCH(n:Label1)--(:rel-label-1)--(z1:Label2)
Followed by the 2 optional Matches to retrieve :Label3 and :rel-label-2
我想用下表结构获得数据

| LABEL1 | LABEL2 |   
|--------|--------| 
但如此

如果没有外部边界:rel-label-2,则从Label2节点, 在表中,标签3为空,Label2节点将仅出现在一行中

如果没有来自Label3节点的Inbound:rel-label-2, 在表中,标签2为空,而Label3节点将仅出现在一行中

现在,我能够根据结构中第一行的匹配生成笛卡尔积:

:Label1 -[:rel-label-1]- :Label2
It may happen that :Label1 -- :Label3
And sometime :Label2 -[:rel-label-2]- :Label3
MATCH(n:Label1)--(:rel-label-1)--(z1:Label2)
Followed by the 2 optional Matches to retrieve :Label3 and :rel-label-2
请在下面找到一个图形和密码预期表格结果的示例
这里有一个可能的解决方案。它将其分解为三个部分,将每个部分的结果保存在一个集合中,然后在最后返回它们

// find the blue and yellow with a direct conneciton
MATCH (b:Blue)--(y:Yellow)
WITH [b.name, y.name] AS pair
// keep them in a collection of pairs
WITH collect(pair) AS pairs

// find the blues connected to alpha and not a yellow
MATCH (b:Blue)<--(:Alpha)
WHERE NOT (b)--(:Yellow)
// add them to the pairs collection
WITH pairs + [[b.name, null]] AS pairs

// find the yellows connected to alpha and not a blue
MATCH (y:Yellow)<--(:Alpha)
WHERE NOT (:Blue)--(y)
// add them to the pairs collection
WITH pairs + [[null, y.name]] AS pairs

// unwind the collection
UNWIND pairs AS pair
RETURN pair[0] AS blue, pair[1] AS yellow
//使用直接连接查找蓝色和黄色
火柴(b:蓝色)--(y:黄色)
以[b.name,y.name]为对
//把它们成对地放在一起
以收集(对)为对
//查找连接到alpha的蓝色,而不是黄色

匹配(b:蓝色)您能否澄清您的2
IF
声明?也许用一些注释过的伪代码来编写它们?根据请求,我添加了一个示例。