Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j-仅当所有节点对之间存在关系属性时才返回路径_Neo4j_Cypher - Fatal编程技术网

Neo4j-仅当所有节点对之间存在关系属性时才返回路径

Neo4j-仅当所有节点对之间存在关系属性时才返回路径,neo4j,cypher,Neo4j,Cypher,比如说,我有一个路径a->B->C->D,并且这些关系有一个属性val。 现在,我必须从路径中选择任意两个节点,如果rel.val>0.8 如果对所有节点对都为true,则返回路径 例: 这是我的问题(当然问题是错的): MATCH p=(a{word:“quality”})-[r*1..2]>(b) 其中无(n在节点(p)中,其中大小(过滤器(x在节点(p)中,其中n=x))>1) 匹配q=(a)-(r:coocr]->(b),其中a在节点(p)中,b在节点(p)中,而不是b=a和无(rel在

比如说,我有一个路径a->B->C->D,并且这些关系有一个属性val。 现在,我必须从路径中选择任意两个节点,如果rel.val>0.8 如果对所有节点对都为true,则返回路径

例:

这是我的问题(当然问题是错的):

MATCH p=(a{word:“quality”})-[r*1..2]>(b)
其中无(n在节点(p)中,其中大小(过滤器(x在节点(p)中,其中n=x))>1)
匹配q=(a)-(r:coocr]->(b),其中a在节点(p)中,b在节点(p)中,而不是b=a和无(rel在rels(q)中,rel.val<0.8)
返回p

总之,您希望
匹配一个路径,然后确保路径中的所有节点对都通过满足特定条件的关系连接(
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
//像以前一样匹配您的路径
匹配p=(a:Uselabel{word:“quality”})-[r:USETYPE*1..2]>(b)
//使用“展开”从路径中获取节点
将节点(路径)展开为x
//执行此操作两次以将节点匹配到自身
将节点(路径)展开为y
//匹配你的关系
匹配(x)-[rel:USETYPE]-(y)
//你们关系的标准
其中相对值>0.8
//仅当两个不同的节点
其中x和y
//获得成对的计数
对于p,将(不同的rel)计数为num_对
//现在我不知道如何获得/比较节点数的阶乘:)
返回num_对

我没有找到阶乘的内置函数,所以你必须研究一下

我不完全明白。。。例如,
a
C
之间是否存在关系,或者您是指
a
B
B
C
之间的关系之和?是的,路径中的每个节点之间都存在关系。对于路径中存在的任何两个节点,应与val>0.8有关系。在我的问题中,A是起始节点,D是路径中的最后一个节点,即使这两个节点在图中的关系val>0.8。请使用label+index来查找您的单词node。您可以用一个示例@Micheal Hunger详细说明您的解决方案,使用rel属性上的Where All()进行一些更改。是的,我应该想到
all()
。我正忙着寻找阶乘函数;)非常感谢你@马丁·普劳斯
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 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