Neo4j基本操作

CQL:

create:创建节点,关系和属性
match:检索有关节点,关系和属性数据
return: 返回查询结果
where:提供条件过滤检索数据
delete: 删除节点和关系的属性
order by :排序检索数据
set :添加或更新标签
peoperties 属性

节点:()
关系:[ ]
 

通过文件创建关系:

load csv from "file:///data.csv" as line
create (:HLRelation{from:line[1],relation:line[3],to:line[0]})
 

通过文件创建结点:

load csv from "file:///data.csv" as line
create (:person2{name:line[0]})
 

创建图谱:

match(n:p1),(m:HLRelation),(s:p2) where m.from=n.name and m.to=s.name
create (n)-[:HL关系{relation:m.relation}]->(s)
return n.name,m.relation,s.name
 

处理结点重复问题:

找到重复的数据
match (n:Location) return count(n); # 13
match (n:Location) return count(distinct n.city); # 5 说明有6个是重复的
# 查看重复的id
match (n:Location), (m:Location) where n.city = m.city and id(n) <> id(m) return n,id(n), m, id(m); 

删除该id所在的关系
match (n:en5)-[r:Relation]->(m:en5) where id(m)=6 delete r;

删除该id
match (n:Location) where id(n)=6 delete n;
match (n:Location) where id(n) in [62,63,82] delete n;

检查
match (n:Location) return count(n); # 5
match (n:Location) return count(distinct n.city); # 5 说明没有重复的了

 

中医药数据集暂时不公开,可以用开源数据集代替:http://www.openkg.cn/group/medicine

posted @ 2022-05-26 23:50  XA科研  阅读(133)  评论(0编辑  收藏  举报