使用 neo4j 构建知识图谱, neo4j 的使用就自行百度吧

1. 首先用 python 连接 neo4j,详细参考下面的代码

    没有安装 py2neo 和 pandas 的使用 pip install 一下

2. 然后 neo4j 不允许有空值,所以使用函数把空值填充一下,填充内容自己定

3. 最后遍历导入数据的每一行,创建新的结点即可

笔者这里的数据集均为属性,没有创建其他关系,后续用到笔者还会分享

from py2neo import Graph,Node,Relationship,NodeMatcher

import pandas as pd

# 连接Neo4j数据库,http://localhost:7474这个一般是默认的端口,auth参数第一个是你的账户名,第二个是你的密码

graph = Graph('http://localhost:7474',auth=("neo4j", "123456"),name='neo4j')

# 读取数据集,参数为数据集的位置,最好别加中文路径。前面的r是禁止转义的意思,就比如\n,你不加r就给你转成换行符了

resume = pd.read_csv(r'D:\neo4j-community-5.17.0\import\data_all.csv')

# 这几个是读取每一列的值,把空的值赋值为字符串未知,不然无法导入

resume['address'] = resume['address'].fillna('未知')

resume['last_active'] = resume['last_active'].fillna('未知')

resume['company'] = resume['company'].fillna('未知')

resume['title'] = resume['title'].fillna('未知')

resume['salary'] = resume['salary'].fillna('未知')

resume['education'] = resume['education'].fillna('未知')

resume['description'] = resume['description'].fillna('未知')

resume['hiring_manager'] = resume['hiring_manager'].fillna('未知')

# 遍历读取的每一行,添加结点

for i in resume.values:

a = Node('resume',id=i[0],company=i[1],title=i[2],salary=i[3],education=i[4],description=i[5],hiring_manager=i[6],last_active=i[7],address=i[8],link=i[9])

graph.create(a)

推荐链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: 


大家都在找:

知识图谱:知识图谱怎么做

人工智能:人工智能技术应用

大家都在看: