|
@@ -1,8 +1,10 @@
|
|
# 封装mysql执行函数、创建节点函数
|
|
# 封装mysql执行函数、创建节点函数
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
-from app.core.graph.graph_operations import connect_graph
|
|
|
|
|
|
+from app.core.graph.graph_operations import connect_graph, get_node as graph_get_node
|
|
from py2neo import Node, RelationshipMatch
|
|
from py2neo import Node, RelationshipMatch
|
|
|
|
+import logging
|
|
|
|
|
|
|
|
+logger = logging.getLogger(__name__)
|
|
db = SQLAlchemy()
|
|
db = SQLAlchemy()
|
|
|
|
|
|
def execute_sql(cur, sql, params):
|
|
def execute_sql(cur, sql, params):
|
|
@@ -28,29 +30,26 @@ def sql_execute_result(sql):
|
|
|
|
|
|
|
|
|
|
# 创建或获取节点
|
|
# 创建或获取节点
|
|
|
|
+"""
|
|
def create_or_get_node(label, **properties):
|
|
def create_or_get_node(label, **properties):
|
|
- node = connect_graph.nodes.match(label, **properties).first()
|
|
|
|
|
|
+ node = connect_graph().nodes.match(label, **properties).first()
|
|
if node is None:
|
|
if node is None:
|
|
node = Node(label, **properties)
|
|
node = Node(label, **properties)
|
|
- connect_graph.create(node)
|
|
|
|
- return node
|
|
|
|
|
|
+ connect_graph().create(node)
|
|
|
|
+ return node
|
|
|
|
+"""
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
# 查询是否存在节点
|
|
# 查询是否存在节点
|
|
|
|
+"""
|
|
def get_node(label, **properties):
|
|
def get_node(label, **properties):
|
|
node = connect_graph.nodes.match(label, **properties).first()
|
|
node = connect_graph.nodes.match(label, **properties).first()
|
|
# 如果没有找到匹配的节点,node 将会是 None
|
|
# 如果没有找到匹配的节点,node 将会是 None
|
|
- return node
|
|
|
|
|
|
+ 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
|
|
|
|
|
|
|
|
|
|
|
|
# 关系权重生成
|
|
# 关系权重生成
|