简体   繁体   English

Cypher - 匹配具有相似关系的节点根据相同关系的数量对结果进行排序

[英]Cypher - match nodes with similar relations rank result based on number of identical relations

I have a graph where node/relations look like:我有一个图表,其中节点/关系如下所示:

(n:Entity)-[r:HasAttribute]->(a:Attribute)

All Entity- and Attibute-nodes have a property called id_obj to identify each node Lets say I have an Entity with id_obj '111' (n:Entity {id_obj:'111'}) and wants to find all other Entity-nodes that has same Attributes as Entity-111 ie find them having the same Attribute-nodes with same id_obj and rank the result (other Entity nodes) based on the number of same Attribute-nodes.... How do I do that?所有实体节点和属性节点都有一个名为 id_obj 的属性来标识每个节点假设我有一个 id_obj '111' (n:Entity {id_obj:'111'}) 的实体,并且想要找到所有其他实体节点与 Entity-111 相同的属性,即发现它们具有相同的属性节点和相同的 id_obj,并根据相同属性节点的数量对结果(其他实体节点)进行排名……我该怎么做?

I have been looking at: https://neo4j.com/docs/graph-data-science/current/algorithms/alpha/filtered-node-similarity/ but I cant figure out how I can start with one start node (Entity-111) and compare all others.我一直在看: https://neo4j.com/docs/graph-data-science/current/algorithms/alpha/filtered-node-similarity/但我不知道如何从一个起始节点开始(实体- 111) 并比较所有其他人。 In examples on page it seems like you comparing all nodes and rank them在页面上的示例中,您似乎比较了所有节点并对它们进行排名

Thanks!谢谢!

You can filter the source node(s) by specifying on the sourceNodeFilter configuration parameter.您可以通过指定sourceNodeFilter配置参数来过滤源节点。 The sourceNodeFilter can be a single node id (or a list of node ids) or single node (or a list of nodes) or a label. sourceNodeFilter 可以是单个节点 ID(或节点 ID 列表)或单个节点(或节点列表)或 label。

In my example below, I will filter only 'Alice' in line #1 and call it alice.在下面的示例中,我将仅过滤第 1 行中的“Alice”并将其命名为 alice。

MATCH (alice:Person) where alice.name = 'Alice'
CALL gds.alpha.nodeSimilarity.filtered.stream('myGraph', {sourceNodeFilter: alice, targetNodeFilter:'Singer' } )
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY similarity DESCENDING, Person1, Person2

Result:结果:

╒═════════╤═════════╤══════════════════╕
│"Person1"│"Person2"│"similarity"      │
╞═════════╪═════════╪══════════════════╡
│"Alice"  │"Bob"    │0.6666666666666666│
├─────────┼─────────┼──────────────────┤
│"Alice"  │"Carol"  │0.3333333333333333│
└─────────┴─────────┴──────────────────┘

Thus, in your example;因此,在您的示例中;

 MATCH (n:Entity {id_obj:'111'}) 
 CALL gds.alpha.nodeSimilarity.filtered.stream('yourGraph', {sourceNodeFilter: n, targetNodeFilter:'Entity' } )
 and so on...

Reference: https://neo4j.com/docs/graph-data-science/current/algorithms/alpha/filtered-node-similarity/#algorithms-filtered-node-similarity-filter-configuration参考: https://neo4j.com/docs/graph-data-science/current/algorithms/alpha/filtered-node-similarity/#algorithms-filtered-node-similarity-filter-configuration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM