数据集
![]()
import py2neo
import pandas as pd
from py2neo import Graph, Node, Relationship, Subgraph
g=Graph('http://localhost:7474',user='neo4j',password='neo4j')
df = pd.read_csv('triples.csv',encoding='gbk')
a = df[['entity','entitytag']]
b = df[['tail','tail-tag']]
b.columns = ['entity','entitytag']
entity = pd.concat([a,b])
# 因为头实体尾实体有些重复的,对实体去重
entity.drop_duplicates(inplace=True)
print(entity)
node_lis = []
# 创建节点
for i in entity.values:
node = Node(i[1], name = i[0])
node_lis.append(node)
nodes=Subgraph(node_lis)
g.create(nodes)
# triple去重
df.drop_duplicates(inplace=True)
# 创建关系集合,为第一步创建的节点之间添加边
lis = []
count = 0
for i in df.values:
count += 1
print(count)
c = g.nodes.match(i[1], name=i[0]).first()
d = g.nodes.match(i[3], name=i[2]).first()
rel_a = Relationship(c, str(i[4]), d)

最低0.47元/天 解锁文章
1211

被折叠的 条评论
为什么被折叠?



