做相亲网站犯法吗,用邮箱做网站,怎么一键打开两个wordpress,那个网站做推广好文章目录 摘要前置NodeMatcher RelationshipMatcher创建节点查询获取节点节点有则查询#xff0c;无则创建创建关系查询关系关系有则查询#xff0c;无则创建 Cypher语句创建节点 摘要
利用py2neo包#xff0c;实现把excel表里面的数据#xff0c;插入到neo4j 图数据… 文章目录 摘要前置NodeMatcher RelationshipMatcher创建节点查询获取节点节点有则查询无则创建创建关系查询关系关系有则查询无则创建 Cypher语句创建节点 摘要
利用py2neo包实现把excel表里面的数据插入到neo4j 图数据库中
创建新(节点或关系)到neo4j图数据库中能够获取neo4j 中已有的(节点或关系)不再创建新(节点或关系)
进阶, 敬请期待案例
前置
安装py2neo: pip install py2neo 安装neo4j软件请自行安装
NodeMatcher RelationshipMatcher 代码由 Jupyter 编写建议使用vscode from py2neo import Graph, Node, NodeMatcher, RelationshipMatcher
import pandas as pd# 连接到Neo4j数据库
graph Graph(bolt://localhost:7687, auth(neo4j, 你设置的密码)) node_matcher NodeMatcher(graph)
relationship_matcher RelationshipMatcher(graph)TODO: 设置neo4j 远程连接 创建节点
node Node(Person, nameAlice, age18)
graph.create(node)查询获取节点
# 拿到匹配到的第一个节点
node_matcher.match(Person, nameAlice).first()# 拿到可匹配到的所有
node_matcher.match(Person, nameAlice).all()节点有则查询无则创建
def get_node(class_, **kwargs):if node : node_matcher.match(class_, **kwargs):# 节点存在则获取return node.first()else:# 节点不存在则创建node Node(class_, **kwargs)graph.create(node)return node创建关系
Alice - Friend - Bob
node1 get_node(Person, nameAlice, age21)
node2 get_node(Person, nameBob, age20)graph.create(Relationship(node1, Friend, node2))查询关系
查询 node1 和 node2 之间是否有 Friend 关系
node1 get_node(Person, nameAlice, age21)
node2 get_node(Person, nameBob, age20)relationship_matcher.match([node1, node2],r_typeFriend).first()关系有则查询无则创建
def get_relation(node1, node2, r_type):if r : relationship_matcher.match([node1, node2],r_typer_type):return r.first()else:r Relationship(node1, r_type, node2)graph.create(r)return r# 查询已有关系
get_relation(node1, node2, Friend)
# 创建新关系
get_relation(node1, node2, Classmate)Cypher语句
虽然 在 NodeMatcher RelationshipMatcher 介绍的接口已经能够满足大部分情况的使用本文仍想提供一种使用cypher语句的插入数据到neo4j图数据库的思路。
创建节点
graph.run(create (n:Person {name:js}) return n
)graph.run(MERGE (n:Person {name: $name}) \ON CREATE SET n.created_at timestamp() \return n,nameCyder
)