我对 Neo4j 很陌生。
附图中有 13 个节点组。
例如,
['img8','img9','img47','img50','img51'] 是一组
['img20', 'img21'] 是另一组。
像这样,我们在附图中就有 13 个节点集。
我需要类似的输出。
[[集合1],[集合2],.....,[集合13]]
如果您安装 Neo4j 图形数据科学 (GDS) 插件,则可以使用社区检测算法。特别是,弱连接组件(WCC)算法将对您的用例有用。这是其文档的片段:
弱连通分量 (WCC) 算法找到一组 有向图中和无向图中的连接节点。两个节点是 连接,如果它们之间存在路径。所有节点的集合 相互连接形成一个组件。相比之下 强连通分量(SCC),关系的方向 不考虑两个节点之间的路径。
例如,如果您只关心
Img
节点(具有 name
属性)和 DISTANCE
关系,您可以执行以下操作:
// Create an in-memory GDS projection for the Img nodes and DISTANCE relationships
CALL gds.graph.project('imgs', 'Img', 'DISTANCE') YIELD graphName
// Run WCC algorithm to find each "component", in which every pair of nodes is connected by some path (ignoring directionality)
CALL gds.wcc.stream('imgs', {}) YIELD nodeId, componentId
// For each component, collect a list of the names of all nodes in that component
WITH componentId, COLLECT(gds.util.asNode(nodeId).name) AS names
// Collect all those lists into an outer list (this is the result you asked for)
RETURN COLLECT(names) AS result
GDS 投影将继续占用服务器上的内存,直到您删除投影或重新启动 Neo4j。要删除名为“imgs”的投影,请执行以下操作:
CALL gds.graph.drop('imgs')
以上只是 GDS 的皮毛,但应该可以帮助您实现用例。