使用Cypher查找Neo4j中条件对之间的所有匹配
我们需要为每种类型的特定节点创建一份关于公共源的报告,以解释: 考虑节点的类型。类型= [“苹果”、“Windows”、“Linux”、“其他”)以及表格的关系。 (源:阳极)-[r:连接到]->(目标:阳极) 因此,每种类型的来源为:使用Cypher查找Neo4j中条件对之间的所有匹配,neo4j,cypher,Neo4j,Cypher,我们需要为每种类型的特定节点创建一份关于公共源的报告,以解释: 考虑节点的类型。类型= [“苹果”、“Windows”、“Linux”、“其他”)以及表格的关系。 (源:阳极)-[r:连接到]->(目标:阳极) 因此,每种类型的来源为: match (source:ANode)-[r:ConnectedTo]->(target:ANode) return distinct target.type, source.name 我们需要为每个类型的成对组合确定重复源,因此,“Apple”和“W
match (source:ANode)-[r:ConnectedTo]->(target:ANode)
return distinct target.type, source.name
我们需要为每个类型的成对组合确定重复源,因此,“Apple”和“Windows”之间、“Windows”和“Linux”之间的重复源等等
我尝试了以下方法,但似乎仅适用于第一对组合:
match (source:ANode)-[r:ConnectedTo]->(target:ANode)
where target.type="Apple"
return distinct target.type, source.name
UNION
match (source:ANode)-[r:ConnectedTo]->(target:ANode)
where target.type="Windows"
return distinct target.type, source.name
我已经可以使用以下代码确定任意两个系统之间的公共源:
Match (node1:ANode)<-[:ConnectsTo]-(src)-[:ConnectsTo]->(node2:ANode)
where ID(node1)<ID(node2)
return node1.type,node1.name,node2.type,node2.name,src.name
匹配(节点1:阳极)(节点2:阳极de)
其中ID(node1)[编辑]
可以使用获取每个源/目标类型对的不同源名称集合:
MATCH (source:ANode)-[r:ConnectedTo]->(target:ANode)
RETURN
source.type AS sourceType,
target.type AS targetType,
COLLECT(DISTINCT source.name) AS sourceNames;
虽然这会返回每种类型的源代码,但我正在寻找类型之间的公共源代码。我已经可以使用如下代码确定任意两个系统之间的公共源:Match(node1:aneon)(node2:aneon),其中ID(node1)不确定我是否正确理解您想要什么,但我已经编辑了我的答案,以展示如何为每个源/目标类型对获取一组不同的源名称。以下是我使用的解决方案:以下是我使用的解决方案:code
MATCH(target2:ANode)(target1:ANode)其中ID(target1)ID(target2)返回target1.type,count(不同的源)order by target1.typecode
这将生成具有相应公共源的类型对矩阵。