Neo4j-从neo4j数据库中提取所有子图 [英] Neo4j - extract all subgraphs from neo4j database

查看:1478
本文介绍了Neo4j-从neo4j数据库中提取所有子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与在此处问过的问题类似的问题,但是,提出的解决方案对我不起作用.

I have a similar question to the one asked here, however, the solution proposed didn't work for me.

我的Neo4j数据库有很多子图,每个子图包含不同数量的节点.

My Neo4j database has a lot of sub-graphs, each one of them contains varying number of nodes.

我想提取某种列表,其中包含所有分离的子图.

I would like to extract some kind of a list which will contain all sub-graphs separated.

在给定的示例中,我想获得3个组,其中每个组包含该组代表的子图中的所有节点.

In the example given, I would like to get 3 groups, where each group contains all the nodes in the sub-graph which the group represents.

如何通过Cypher查询获取所有节点组?

How can I get all groups of nodes by Cypher query?

我为此问题找到的所有解决方案都需要"root"节点,在这种情况下,我没有这个节点.

All the solutions that I have found for this problem require "root" node which I don't have in this case.

推荐答案

您可以使用图算法插件,特别是连接组件算法标记图形中所有孤立的子图,然后将它们导出,并在以后按集合ID导出时对其进行分组.

You could use graph algorithms plugin and specifically connected components algorithm to label all the isolated subgraphs in your graph and then export them and group them later when exported by set id.

示例:

创建样本图

MERGE (nAlice:User {id:'Alice'})
MERGE (nBridget:User {id:'Bridget'})
MERGE (nCharles:User {id:'Charles'})
MERGE (nDoug:User {id:'Doug'})
MERGE (nMark:User {id:'Mark'})
MERGE (nMichael:User {id:'Michael'})

MERGE (nAlice)-[:FRIEND]->(nBridget)
MERGE (nAlice)-[:FRIEND]->(nCharles)
MERGE (nMark)-[:FRIEND]->(nDoug)
MERGE (nMark)-[:FRIEND]->(nMichael);

运行连接的组件(unionFind)算法,并在同一子图中返回节点:

Run connected components (unionFind) algorithm and return nodes in the same subgraph:

CALL algo.unionFind.stream('User', 'FRIEND', {})
YIELD nodeId,setId
RETURN setId,collect(algo.getNodeById(nodeId)) AS nodes_from_specific_subgraph

这将返回:

╒═══════╤══════════════════════════════════════════════════╕
│"setId"│"specific_subgraph"                               │
╞═══════╪══════════════════════════════════════════════════╡
│4      │[{"id":"Doug"},{"id":"Mark"},{"id":"Michael"}]    │
├───────┼──────────────────────────────────────────────────┤
│0      │[{"id":"Alice"},{"id":"Bridget"},{"id":"Charles"}]│
└───────┴──────────────────────────────────────────────────┘

这篇关于Neo4j-从neo4j数据库中提取所有子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆