安装
- 使用 docker 安装 Neo4j
- 拉取最新的 Neo4j 镜像
docker pull neo4j
运行
docker run -it -d -p 7474:7474 -p 7687:7687 neo4j
http://localhost:7474
- 用户名和密码均为 neo4j
- 初次登陆会要求修改密码
Python 操作
from py2neo import Graph, Node, Relationship
graph = Graph('http://localhost:7474', username='neo4j', password='123456')
label_1 = "dnn_1"
node_1 = Node(label_1, name="案件1")
graph.create(node_1)
relation_1_a = Relationship(node_1, relation_name, node_a)
graph.create(relation_1_a)
简单示例
from py2neo import Graph, Node, Relationship
graph = Graph('http://localhost:7474', username='neo4j', password='123456')
label_1 = "dnn_1"
label_2 = "dnn_2"
relation_name = "CRIME"
node_1 = Node(label_1, name="案件1")
node_2 = Node(label_1, name="案件2")
node_3 = Node(label_1, name="案件3")
node_a = Node(label_2, name="A")
node_b = Node(label_2, name="B")
node_c = Node(label_2, name="C")
node_d = Node(label_2, name="D")
node_e = Node(label_2, name="E")
node_f = Node(label_2, name="F")
node_g = Node(label_2, name="G")
node_h = Node(label_2, name="H")
graph.create(node_1)
graph.create(node_2)
graph.create(node_3)
graph.create(node_a)
graph.create(node_b)
graph.create(node_c)
graph.create(node_d)
graph.create(node_e)
graph.create(node_f)
graph.create(node_g)
graph.create(node_h)
relation_1_a = Relationship(node_1, relation_name, node_a)
relation_1_b = Relationship(node_1, relation_name, node_b)
relation_1_c = Relationship(node_1, relation_name, node_c)
relation_1_d = Relationship(node_1, relation_name, node_d)
relation_2_c = Relationship(node_2, relation_name, node_c)
relation_2_b = Relationship(node_2, relation_name, node_b)
relation_2_e = Relationship(node_2, relation_name, node_e)
relation_3_f = Relationship(node_3, relation_name, node_f)
relation_3_g = Relationship(node_3, relation_name, node_g)
relation_3_h = Relationship(node_3, relation_name, node_h)
graph.create(relation_1_a)
graph.create(relation_1_b)
graph.create(relation_1_c)
graph.create(relation_1_d)
graph.create(relation_2_c)
graph.create(relation_2_b)
graph.create(relation_2_e)
graph.create(relation_3_f)
graph.create(relation_3_g)
graph.create(relation_3_h)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)