基于公共属性合并节点,并将所有属性添加到初始节点

问题描述 投票:0回答:2

在此图像中,您可以看到节点中的所有属性,我想要实现的是基于CUI(id)合并节点并将这些属性添加到一个初始节点。

In this image you can see all the properties from a node, what I want to achieve is to merge the nodes based on CUI (id) and add those properties to one initial node

我试过了

START first=node(*), second=node(*) 
WHERE exists (first.id) and exists (second.id) 
WITH first, second
SKIP 20000 LIMIT 20000
WHERE first.id= second.id
SET first=second; 

但没有变化

然后我试着打电话给APOC

match (f:Disease),(b:Disease) where f.id=b.id 
CALL apoc.refactor.mergeNodes([f,b]) yield node 
return "none";

这给了我一个错误

ServiceUnavailable:WebSocket连接失败。由于Web浏览器中的安全限制,此Neo4j驱动程序无法使用此故障原因。请使用您的浏览器开发控制台确定失败的根本原因。常见原因包括数据库不可用,使用错误的连接URL或临时网络问题。如果您已启用加密,请确保您的浏览器配置为信任Neo4j配置使用的证书。 WebSocket readyState是:3

有人可以帮助查询合并节点并添加属性,这样我就不会丢失信息吗?

neo4j cypher
2个回答
1
投票

首先,运行此命令以创建唯一性约束并在疾病的id属性上添加索引。 [重要]

CREATE CONSTRAINT ON (d:Disease) ASSERT d.id IS UNIQUE

然后运行以下查询以加载数据。如果节点不存在,这将创建节点并设置属性。如果节点已存在,则会附加值。

USING PERIODIC COMMIT 
LOAD CSV WITH HEADERS FROM 'file:///ConditionConcepts.csv' AS line FIELDTERMINATOR '\t'
MERGE (disease:Disease {id: line.CUI}) 
ON CREATE SET 
    disease.name_doctor = line.name, 
    disease.relevance = line.cui_relevance, 
    disease.trials = line.trials_count, 
    disease.search = line.search_frequency, 
    disease.select = line.select_frequency
ON MATCH SET
    disease.name_doctor = disease.name_doctor+", "+line.name, 
    disease.relevance = disease.relevance+", "+line.cui_relevance, 
    disease.trials = disease.trials+", "+line.trials_count, 
    disease.search = disease.search+", "+line.search_frequency, 
    disease.select = disease.select+", "+line.select_frequency

0
投票

我可以告诉你一个更简单的例子,我想要什么this is the initial situation, all id are the same

在我应用以下查询后

MATCH (o:Disease),(b:Disease) 
WHERE o.id=b.id and o<>b and o.name_doctor<>b.name_doctor 
SET o.name_doctor=o.name_doctor+", "+b.name_doctor 
RETURN o,b;

我会得到这个结果

after applying the query

但这不是我想要的,最后,我需要有一个节点,它将具有其他节点的属性,就像这个ideal situation

也许有一种方法可以在创建时执行此操作,我必须加载CSV文件才能获得数据,如果我使用合并(而不是创建)或约束,我将丢失属性。

我需要找到一种方法来创建节点而不会丢失任何数据。

© www.soinside.com 2019 - 2024. All rights reserved.