| 12345678910111213141516171819202122232425262728293031323334353637 | '''图谱相关连接配置'''from flask import Flaskfrom py2neo import Graphfrom configs.nacos_bak import nacos_service_singlefrom py2neo import Nodeapp = Flask(__name__)configs= nacos_service_single.get_nacos_configs()neo4j_url = configs['neo4j_url']username = configs['neo4j_username']password = configs['neo4j_password']connect_graph = Graph(neo4j_url, auth=(username, password))# 创建或获取节点def create_or_get_node(label,**properties):    node = connect_graph.nodes.match(label,**properties).first()    if node is None:        node = Node(label,**properties)        connect_graph.create(node)    return node# 查询是否存在节点def get_node(label,**properties):    node = connect_graph.nodes.match(label,**properties).first()    # 如果没有找到匹配的节点,node 将会是 None    return node# 查询是否存在关系def relationship_exists(start_node, rel_type, end_node, **properties):    matcher = connect_graph.match(nodes=[start_node, end_node], r_type=rel_type)    # 如果需要匹配关系的属性    if properties:        matcher = matcher.where(**properties)    result = matcher.first()    return result is not None
 |