我想确定哪些模拟人生、哪些门是打开的。
使用以下方式创建数据:
CREATE
(a:Gate {name: 'gate a'}),
(b:Gate {name: 'gate b'}),
(c:Gate {name: 'gate c'}),
(x1:X {name: 'sim 1'}),(x2:X {name: 'sim 2'}), (x3:X {name: 'sim 3'}),
(e1:E {name: 'event 1'}),(e2:E {name: 'event 2'}), (e3:E {name: 'event 3'}),
(e1)-[:AND]->(a),
(e1)-[:AND]->(b),
(e2)-[:AND]->(b),
(e1)-[:AND]->(c),
(e2)-[:AND]->(c),
(e3)-[:AND]->(c),
(x1)-[:HAS]->(e1),
(x2)-[:HAS]->(e1),
(x2)-[:HAS]->(e2),
(x3)-[:HAS]->(e2),
(x3)-[:HAS]->(e1),
(x3)-[:HAS]->(e3)
假设您的数据库没有重复的
HAS
或 AND
关系(同一对节点之间),您可以:
gIdCountMap
)。gIdCountMap
中计数的 sim/门对。例如(这也按 sim 对结果进行排序):
MATCH (e)-[:AND]->(g:Gate)
WITH ELEMENTID(g) as gId, COUNT(e) AS gEventCount
WITH apoc.map.fromPairs(COLLECT([gId, gEventCount])) AS gIdCountMap
MATCH (sim:X)-[:HAS]->(event)-[:AND]->(gate)
WITH sim, gate, gIdCountMap, COUNT(event) AS sgEventCount
WHERE gIdCountMap[ELEMENTID(gate)] = sgEventCount
RETURN sim, gate
ORDER BY sim
结果是:
╒════════════════════╤════════════════════════╕
│sim │gate │
╞════════════════════╪════════════════════════╡
│(:X {name: "sim 1"})│(:Gate {name: "gate a"})│
├────────────────────┼────────────────────────┤
│(:X {name: "sim 2"})│(:Gate {name: "gate a"})│
├────────────────────┼────────────────────────┤
│(:X {name: "sim 2"})│(:Gate {name: "gate b"})│
├────────────────────┼────────────────────────┤
│(:X {name: "sim 3"})│(:Gate {name: "gate a"})│
├────────────────────┼────────────────────────┤
│(:X {name: "sim 3"})│(:Gate {name: "gate b"})│
├────────────────────┼────────────────────────┤
│(:X {name: "sim 3"})│(:Gate {name: "gate c"})│
└────────────────────┴────────────────────────┘