找到一组节点,其中至少包含一个具有特定 属性 值的子集
Find a set of nodes containing certainly at least one subset having a certain property value
我需要一个 Cypher 的帮助,它确保生成的一组节点肯定包含至少一个验证特定 属性 值的子集。
每个结果集都包含子集。
我想要的目标集应该至少在结果子集中有一个验证 属性 值的子集。
假设我有:
R包括C包括S
也就是说
(c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
假设
R={r1,r2,r3,...........rn}
C={c1,c2,c3,...........cn}
S={sb1,sb2,sb3,...........sbn}
where sb1={s11,s12,s13.....s1n}
sb2={s21,s22,s23.....s2n}
sb3={s31,s32,s33.....s3n}
.........................
sbn={sn1,sn2,sn3.....snn}
例如
MATCH (c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
WHERE
r.r='BLABLA' AND
r.identifier='50' AND
c.identifier='504'
return s.identifier as identifier
将 return 仅包含一组标识符,其中仅包含一个验证 c.identifier='504'
的子集
并且我想要 return 一个包含所有子集的集合(即验证 r.r='BLABLA' AND r.identifier='50')并且在结果中子集 肯定至少有一个子集验证 c.identifier='504'.
我想得到一组结果子集中肯定至少包含一个验证属性值的子集。
我尝试了 where EXISTS 但不幸的是我无法得到我想要的东西。
MATCH (c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
WHERE EXISTS((s)-[*0..]-(c{identifier:'504'}))
AND
r.r='BLABLA'
AND
r.identifier='50'
N.B:节点之间的关系如下:
(s:S)-[rel1:IS_A_S_BELONGING_TO_R*0..1]->(r:R)<-[rel2:IS_A_C_BELONGING_TO*0..1]-(c:C)<-[IS_A_S_BELONGING_TO_THAT_C*0..1]-(s)
非常感谢您的帮助。
更新
假设我有 hierarchy1
R----
----C1
---------s1 have property c{identifier:'504'}
---------s2 have property c{identifier:'504'}
---------s3 have property c{identifier:'504'}
----C2
---------s21 have property c{identifier:'21'}
---------s22 have property c{identifier:'21'}
---------s23 have property c{identifier:'21'}
----C3
----------s31 have property c{identifier:'23'}
----------s32 have property c{identifier:'23'}
----------s33 have property c{identifier:'23'}
另一个 Hierarchy2 与 R、C1、C2、C3 具有相同的名称
R----
----C1
---------s1 DON't have property c{identifier:'504'}**********
---------s2 DON't have property c{identifier:'504'}**********
---------s3 DON't have property c{identifier:'504'}**********
----C2
---------s21 DON't have property c{identifier:'504'}**********
---------s22 DON't have property c{identifier:'504'}**********
---------s23 DON't have property c{identifier:'504'}**********
----C3
----------s31 DON't have property c{identifier:'504'}**********
----------s32 DON't have property c{identifier:'504'}**********
----------s33 DON't have property c{identifier:'504'}**********
当我做我的密码时,我应该让所有节点 s1,s2,s3,s21,s22,s23,s31,s32,s33 包含在 hierarchy1 而不是来自 hierarchy2 因为在 hierarchy1 我至少有一个子集节点 s1 ,s2,s3 具有 属性 c{identifier:'504'}
在层次结构 2 中没有人拥有 c{identifier:'504'} 因此我的密码将忽略第二层次结构。
密码将确保我只得到 hierarchy1 中包含的 s
并且没有来自 hierarchy2 的 s。
因为 R、C1、C2、C3 名称可以在许多层次结构中重复,我有一个参数 c{identifier:XXXX} 密码可以区分它们。
我想我已经掌握了你想要的东西。
这里缺少的部分是 s
节点按 c
节点分组。您需要在此处使用 collect()
将 s
节点收集到列表中,并且通过将 c
节点保留为非聚合变量,它将确保 s
节点根据其相关 c
节点进行分组。
但首先我们必须处理过滤,以确保我们只选择与标识符 504 的 :C 节点匹配的 :R 节点。听起来你的节点很少(或者可能只有一个?):标识符为 504 的 C 节点,所以让我们确保我们只选择链接到所讨论的 :C 节点的 :R 节点,然后在我们过滤后继续到 :S 节点。
附带说明一下,您在查询中两次使用了 r
变量,一次用于 :R 节点,一次用于与 s
节点的可选关系,因此获胜工作。我们可以从关系中删除变量。
MATCH (c:C)
WHERE c.identifier='504'
MATCH (r:R)
WHERE
r.r='BLABLA' AND
r.identifier='50' AND
(c)-[:BELONGING_TO]->(r)
WITH r
MATCH (c:C)-[:BELONGING_TO]->(r)-[*0..1]-(s:S)
WITH c, collect(DISTINCT s) as sList
RETURN c.identifier as cId, [s in sList | s.identifier] as sList
我需要一个 Cypher 的帮助,它确保生成的一组节点肯定包含至少一个验证特定 属性 值的子集。
每个结果集都包含子集。
我想要的目标集应该至少在结果子集中有一个验证 属性 值的子集。
假设我有:
R包括C包括S
也就是说
(c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
假设
R={r1,r2,r3,...........rn}
C={c1,c2,c3,...........cn}
S={sb1,sb2,sb3,...........sbn}
where sb1={s11,s12,s13.....s1n}
sb2={s21,s22,s23.....s2n}
sb3={s31,s32,s33.....s3n}
.........................
sbn={sn1,sn2,sn3.....snn}
例如
MATCH (c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
WHERE
r.r='BLABLA' AND
r.identifier='50' AND
c.identifier='504'
return s.identifier as identifier
将 return 仅包含一组标识符,其中仅包含一个验证 c.identifier='504'
的子集并且我想要 return 一个包含所有子集的集合(即验证 r.r='BLABLA' AND r.identifier='50')并且在结果中子集 肯定至少有一个子集验证 c.identifier='504'.
我想得到一组结果子集中肯定至少包含一个验证属性值的子集。
我尝试了 where EXISTS 但不幸的是我无法得到我想要的东西。
MATCH (c:C)-[:BELONGING_TO]->(r:R)-[r*0..1]-(s:S)
WHERE EXISTS((s)-[*0..]-(c{identifier:'504'}))
AND
r.r='BLABLA'
AND
r.identifier='50'
N.B:节点之间的关系如下:
(s:S)-[rel1:IS_A_S_BELONGING_TO_R*0..1]->(r:R)<-[rel2:IS_A_C_BELONGING_TO*0..1]-(c:C)<-[IS_A_S_BELONGING_TO_THAT_C*0..1]-(s)
非常感谢您的帮助。
更新
假设我有 hierarchy1
R----
----C1
---------s1 have property c{identifier:'504'}
---------s2 have property c{identifier:'504'}
---------s3 have property c{identifier:'504'}
----C2
---------s21 have property c{identifier:'21'}
---------s22 have property c{identifier:'21'}
---------s23 have property c{identifier:'21'}
----C3
----------s31 have property c{identifier:'23'}
----------s32 have property c{identifier:'23'}
----------s33 have property c{identifier:'23'}
另一个 Hierarchy2 与 R、C1、C2、C3 具有相同的名称
R----
----C1
---------s1 DON't have property c{identifier:'504'}**********
---------s2 DON't have property c{identifier:'504'}**********
---------s3 DON't have property c{identifier:'504'}**********
----C2
---------s21 DON't have property c{identifier:'504'}**********
---------s22 DON't have property c{identifier:'504'}**********
---------s23 DON't have property c{identifier:'504'}**********
----C3
----------s31 DON't have property c{identifier:'504'}**********
----------s32 DON't have property c{identifier:'504'}**********
----------s33 DON't have property c{identifier:'504'}**********
当我做我的密码时,我应该让所有节点 s1,s2,s3,s21,s22,s23,s31,s32,s33 包含在 hierarchy1 而不是来自 hierarchy2 因为在 hierarchy1 我至少有一个子集节点 s1 ,s2,s3 具有 属性 c{identifier:'504'} 在层次结构 2 中没有人拥有 c{identifier:'504'} 因此我的密码将忽略第二层次结构。
密码将确保我只得到 hierarchy1 中包含的 s 并且没有来自 hierarchy2 的 s。
因为 R、C1、C2、C3 名称可以在许多层次结构中重复,我有一个参数 c{identifier:XXXX} 密码可以区分它们。
我想我已经掌握了你想要的东西。
这里缺少的部分是 s
节点按 c
节点分组。您需要在此处使用 collect()
将 s
节点收集到列表中,并且通过将 c
节点保留为非聚合变量,它将确保 s
节点根据其相关 c
节点进行分组。
但首先我们必须处理过滤,以确保我们只选择与标识符 504 的 :C 节点匹配的 :R 节点。听起来你的节点很少(或者可能只有一个?):标识符为 504 的 C 节点,所以让我们确保我们只选择链接到所讨论的 :C 节点的 :R 节点,然后在我们过滤后继续到 :S 节点。
附带说明一下,您在查询中两次使用了 r
变量,一次用于 :R 节点,一次用于与 s
节点的可选关系,因此获胜工作。我们可以从关系中删除变量。
MATCH (c:C)
WHERE c.identifier='504'
MATCH (r:R)
WHERE
r.r='BLABLA' AND
r.identifier='50' AND
(c)-[:BELONGING_TO]->(r)
WITH r
MATCH (c:C)-[:BELONGING_TO]->(r)-[*0..1]-(s:S)
WITH c, collect(DISTINCT s) as sList
RETURN c.identifier as cId, [s in sList | s.identifier] as sList