- 首先启动neo4j
./neo4j console
- 连接数据库
from py2neo import Graph, Node, Relationship
graph = Graph("http://localhost:7474", auth=("neo4j", "xxxxxxx"))
- 添加节点
node1 = Node('Person', name='Bob')
graph.create(node1)
node2 = Node('Person', name='Alice')
graph.create(node2)
node3 = Node('animal', name='cat')
graph.create(node3)
node4 = Node('animal', name='dog')
graph.create(node4)
- 添加关系
r1 = Relationship(node2, 'know', node1)
r2 = Relationship(node1, 'know', node3)
r3 = Relationship(node2, 'has', node3)
r4 = Relationship(node4, 'has', node2)
graph.create(r1)
graph.create(r2)
graph.create(r3)
graph.create(r4)
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.csdn.net/weixin_35757704/article/details/112525629,作者:呆萌的代Ma,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。