Neo4j和py2neo用法

py2neo——Neo4j&python的配合使用
https://www.jianshu.com/p/a2497a33390f
以下基于Python2:

安装py2neo模块
pip install py2neo
# 连接Neo4j数据库

from py2neo import Graph,Node,Relationship

test_graph = Graph(
    "http://localhost:7474", 
    username="123456", 
    password="123456"
)

# 节点的建立
test_node_1 = Node("Person",name = "test_node_1")  #上述链接中有点问题,这里改正过来了
test_node_2 = Node("Person",name = "test_node_2") #同上
test_graph.create(test_node_1)
test_graph.create(test_node_2)

# 节点间关系的建立
node_1_call_node_2 = Relationship(test_node_1,'CALL',test_node_2)
node_1_call_node_2['count'] = 1
node_2_call_node_1 = Relationship(test_node_2,'CALL',test_node_1)
node_2_call_node_1['count'] = 2
test_graph.create(node_1_call_node_2)
test_graph.create(node_2_call_node_1)

# 节点/关系的属性赋值以及属性值的更新
node_1_call_node_2['count']+=1
test_graph.push(node_1_call_node_2)

# 通过属性值来查找节点和关系(find,find_one)
find_code_1 = test_graph.find_one(
  label="Person",
  property_key="name",
  property_value="test_node_1"
)
print find_code_1['name']


# 通过节点/关系查找相关联的节点/关系
find_relationship = test_graph.match_one(start_node=find_code_1,end_node=find_code_3,bidirectional=False)
print find_relationship

# match和match_one的参数包括start_node,Relationship,end_node中的至少一个。

match_relation  = test_graph.match(start_node=find_code_1,bidirectional=True)
for i in match_relation:
    print i
    i['count']+=1
    test_graph.push(i)

在 Python 中使用 Neo4j
http://python.jobbole.com/84190/

以下基于Python3

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值