假设我有一个路径A-> B-> C-> D,并且这些关系都有一个属性val。现在,我必须从路径中选择任意两个节点,并且如果rel.val> 0.8并且对于所有这对节点都为true,则返回路径
前任:
P = A-->B-->C-->D
All nodes = [A,B,C,D]
return p if{
rel.val of (A,B) >0.8
rel.val of (A,C) >0.8
rel.val of (A,D) >0.8
rel.val of (B,C) >0.8
rel.val of (B,D) >0.8
rel.val of (C,D) >0.8
}
这是我的查询,(当然查询是错误的):
MATCH p=(a{word:"quality"})-[r*1..2]->(b)
WHERE NONE (n IN nodes(p) WHERE size(filter(x IN nodes(p) WHERE n = x))> 1)
MATCH q = (a)-[r:coocr]->(b) where a in nodes(p) AND b in nodes(p) AND NOT b = a AND None(rel IN rels(q) WHERE rel.val < 0.8 )
RETURN p
总而言之,您需要MATCH
一条路径,然后确保路径中的所有节点对都通过满足特定条件(rel.val > 0.8
)的关系连接。
有趣的问题,我认为这并不是很简单。也许我忽略了一些明显的事情?
这是一个解决问题的方法。您首先MATCH
要建立路径,然后MATCH
在路径中的所有节点之间进行计数,并使用计算关系的数量rel.val > 0.8
。该数量必须是节点数量的阶乘大小(num relationships == (num nodes)!
,可能组合的数量为2)。
以下查询返回关系数,但是我不知道如何将其与节点数的阶乘进行比较:
// match your path like before
MATCH p=(a:Uselabel {word:"quality"})-[r:USETYPE*1..2]->(b)
// use unwind to get the nodes from the path
UNWIND nodes(path) AS x
// do this twice to match the nodes onto themselves
UNWIND nodes(path) AS y
// match your relationship
MATCH (x)-[rel:USETYPE]-(y)
// criterion for your relationship
WHERE rel.val > 0.8
// only if two different nodes
WHERE x <> y
// get the count of pairs
WITH p, count(DISTINCT rel) AS num_pairs
// now I don't know how to get/compare the factorial of the number of nodes :)
RETURN num_pairs
我没有找到阶乘的内置函数,因此您必须对此进行研究。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句