知识图谱学习笔记——我的第一次知识图谱实践

数据集来自OpenKG.CN

代码

from py2neo import *
import pandas as pd
#connect
#g=Graph(host='127.0.0.1',http_port=7474,user='neo4j',password='lan')
g=Graph('http://localhost:7474/',auth=('neo4j',"lan"))
filename="E:\\1\\数据集\\东周列国知识图谱\\kg.xlsx"

try_data=pd.read_excel(filename)
character1=try_data.iloc[1:,0]
character1[0]="齐桓公"

character2=try_data.iloc[1:,1]
character2[0]="齐襄公"

relation=try_data.iloc[1:,2]
relation[0]="关系"
for i in range(len(relation)):
    #build note
    cha1=Node('person',name=str(character1[i]))
    cha2=Node('person',name=str(character2[i]))
#    g.create(cha1)
#    g.create(cha2)

    #build relation
    re=Relationship(cha1,str(relation[i]),cha2)

#    g.create(re)
    g.merge(cha1,'person','name')
    g.merge(cha2,'person','name')
    g.merge(re,'person','name')

效果图展示

知识图谱学习笔记——我的第一次知识图谱实践_第1张图片

你可能感兴趣的:(#,知识图谱,知识图谱,学习,人工智能)