在Neo4j的,我創建了一個小圖有4個節點,其中一些鏈接到其他一些:使用Neo4j的暗號找到哪些節點沒有相互關聯的
CREATE
(a:Room {name:"A"})
-[:DOOR]->
(b:Room {name:"B"})
-[:DOOR]->
(c:Room {name:"C"})
-[:DOOR]->
(d:Room {name:"D"}),
a-[:DOOR]->c,
a-[:DOOR]->d,
b-[:DOOR]->a
RETURN a,b,c,d
我想找到哪個房間不要在它們之間有一扇門。我希望的輸出是這樣的:
{"B": ["D"], "C": ["A", "B"], "D": ["A", "B", "C"]}
我可以爲一個給定的出發點做到這一點...
MATCH (b), (r)
WHERE b.name = "B"
AND NOT (b)-[:DOOR]->(r)
AND b <> r
RETURN r
// Returns Room D
下面是我通過每個可能的迭代貨物邪教僞代碼的節點:
MATCH rooms = (r)
SET output = {}
FOREACH (
room IN nodes(rooms),
exit IN nodes(rooms),
missing = [],
output[room.name] = missing
|
IF room <> exit AND NOT room-[:DOOR]->(exit)
THEN missing = missing + exit
)
RETURN output
請幫我理解如何在Cypher中正確表達這一點。
我在回答之前錯過了編輯,問題是如何針對所有節點對執行此操作? – jjaderberg