1、安装驱动
pip install py2neo
2、插入数据
# -*- coding: UTF-8 -*-
from py2neo import Graph, Node, Relationship
# 连接neo4j数据库,输入地址、用户名、密码
graph = Graph('http://192.168.25.223:7474', username='neo4j', password='123456')
def create_date():
# 创建结点
ts = Node('Person', name='唐僧')
pt = Node('Person', name='菩提祖师')
swk = Node('Person', name='孙悟空')
zbj = Node('Person', name='猪八戒')
ss = Node('Person', name='沙僧')
graph.create(ts)
graph.create(pt)
graph.create(swk)
graph.create(zbj)
graph.create(ss)
jgb = Node('Weapon', name='如意金箍棒')
dp = Node('Weapon', name='九齿钉耙')
xmc = Node('Weapon', name='降魔杵')
graph.create(jgb)
graph.create(dp)
graph.create(xmc)
# 创建关系
r1 = Relationship(ts, '大徒弟', swk)
r2 = Relationship(ts, '二徒弟', zbj)
r3 = Relationship(ts, '三徒弟', ss)
r4 = Relationship(ts, '徒弟', swk)
r5 = Relationship(ts, '徒弟', zbj)
r6 = Relationship(ts, '徒弟', ss)
r7 = Relationship(swk, '师父', ts)
r8 = Relationship(zbj, '师父', ts)
r9 = Relationship(ss, '师父', ts)
r10 = Relationship(swk, '武器', jgb)
r11 = Relationship(zbj, '武器', dp)
r12 = Relationship(ss, '武器', xmc)
r13 = Relationship(swk, '师父', pt)
graph.create(r1)
graph.create(r2)
graph.create(r3)
graph.create(r4)
graph.create(r5)
graph.create(r6)
graph.create(r7)
graph.create(r8)
graph.create(r9)
graph.create(r10)
graph.create(r11)
graph.create(r12)
graph.create(r13)
if __name__ == '__main__':
create_date()
# graph.delete_all()
3、neo4j结果