from py2neo import Graph,Node,Relationship, NodeMatcher, RelationshipMatcher
##连接neo4j数据库,输入地址、用户名、密码
graph = Graph('bolt://xxxxxxxxx:37687', user ='neo4j', password='123456')
def creat_node(lable, name):
node = Node(lable, name=name)
graph.create(node)
return node
def creat_relationship(node1,relationship, node2, _property):
node1_ship_node2 = Relationship(node1, relationship, node2)
if isinstance(_property, dict):
for key in _property:
node1_ship_node2[key]=_property[key]
graph.create(node1_ship_node2)
def node_match():
node_match = NodeMatcher(graph)
node = node_match.match("Paper", ID='09076').where(year=2017) # 匹配指定ID和year的Paper结点
return node
def relationship_match():
relationship_match = RelationshipMatcher(graph)
relation = relationship_match.matcher(r_type="Cited").limit(50)
return relation
参考: 1 Py2neo的基本用法_jian_qiao的博客-优快云博客_py2neo
3 安装 插件
4 docker安装