反思优化1.0(优化隐私输出、时间检索)

This commit is contained in:
lixinyue
2026-01-19 16:28:01 +08:00
parent 871304c89b
commit 5a0d3df689
9 changed files with 173 additions and 170 deletions

View File

@@ -837,12 +837,14 @@ neo4j_query_part = """
WITH DISTINCT m
OPTIONAL MATCH (m)-[rel]-(other:ExtractedEntity)
RETURN
elementId(m) as id,
m.name as entity1_name,
m.description as description,
m.statement_id as statement_id,
m.created_at as created_at,
m.expired_at as expired_at,
CASE WHEN rel IS NULL THEN "NO_RELATIONSHIP" ELSE type(rel) END as relationship_type,
elementId(rel) as rel_id,
rel.predicate as predicate,
rel.statement as relationship,
rel.statement_id as relationship_statement_id,
@@ -855,12 +857,14 @@ neo4j_query_all = """
WITH DISTINCT m
OPTIONAL MATCH (m)-[rel]-(other:ExtractedEntity)
RETURN
elementId(m) as id,
m.name as entity1_name,
m.description as description,
m.statement_id as statement_id,
m.created_at as created_at,
m.expired_at as expired_at,
CASE WHEN rel IS NULL THEN "NO_RELATIONSHIP" ELSE type(rel) END as relationship_type,
elementId(rel) as rel_id,
rel.predicate as predicate,
rel.statement as relationship,
rel.statement_id as relationship_statement_id,

View File

@@ -11,22 +11,28 @@ async def update_neo4j_data(neo4j_dict_data, update_databases):
update_databases: update
"""
try:
# 构建WHERE条件
# 构建WHERE条件 - 只使用elementId
where_conditions = []
params = {}
for key, value in neo4j_dict_data.items():
if value is not None:
param_name = f"param_{key}"
where_conditions.append(f"e.{key} = ${param_name}")
params[param_name] = value
# 优先使用id作为elementId进行查询
if 'id' in neo4j_dict_data and neo4j_dict_data['id'] is not None:
where_conditions.append(f"elementId(e) = $param_id")
params['param_id'] = neo4j_dict_data['id']
else:
# 如果没有id使用其他字段作为条件
for key, value in neo4j_dict_data.items():
if value is not None:
param_name = f"param_{key}"
where_conditions.append(f"e.{key} = ${param_name}")
params[param_name] = value
where_clause = " AND ".join(where_conditions) if where_conditions else "1=1"
# 构建SET条件
# 构建SET条件 - 排除id字段
set_conditions = []
for key, value in update_databases.items():
if value is not None:
if value is not None and key != 'id': # 不更新id字段
param_name = f"update_{key}"
set_conditions.append(f"e.{key} = ${param_name}")
params[param_name] = value
@@ -76,22 +82,28 @@ async def update_neo4j_data_edge(neo4j_dict_data, update_databases):
update_databases: update
"""
try:
# 构建WHERE条件
# 构建WHERE条件 - 只使用elementId
where_conditions = []
params = {}
for key, value in neo4j_dict_data.items():
if value is not None:
param_name = f"param_{key}"
where_conditions.append(f"r.{key} = ${param_name}")
params[param_name] = value
# 优先使用id作为elementId进行查询
if 'id' in neo4j_dict_data and neo4j_dict_data['id'] is not None:
where_conditions.append(f"elementId(r) = $param_id")
params['param_id'] = neo4j_dict_data['id']
else:
# 如果没有id使用其他字段作为条件
for key, value in neo4j_dict_data.items():
if value is not None:
param_name = f"param_{key}"
where_conditions.append(f"r.{key} = ${param_name}")
params[param_name] = value
where_clause = " AND ".join(where_conditions) if where_conditions else "1=1"
# 构建SET条件
# 构建SET条件 - 排除id字段
set_conditions = []
for key, value in update_databases.items():
if value is not None:
if value is not None and key != 'id': # 不更新id字段
param_name = f"update_{key}"
set_conditions.append(f"r.{key} = ${param_name}")
params[param_name] = value
@@ -242,7 +254,16 @@ async def neo4j_data(solved_data):
if key=='expired_at':
updat_expired_at[key] = values[1]
elif key == 'statement_id':
elif key == 'id':
ori_edge[key] = values
updata_edge[key] = values
ori_entity[key] = values
updata_entity[key] = values
ori_expired_at[key] = values
elif key == 'rel_id':
key='id'
ori_edge[key] = values
updata_edge[key] = values