- 按生产 7900 容器黄金清单迁移(compile.manifest 449 条目,0 缺失) - 入口双态:api.app(生产同源 3 路由)/ api.main(裁剪 11 路由族 91 路径) - 修复:advanced/__init__ 空文件(包标记误覆盖,已从主项目恢复) - 修复:api/rag_routes.py 跨环境 site-packages 注入改 LEGACY_GF_SITE_PACKAGES 门控 - 修复:scripts/utils 缺失(动态加载 reasoning_engine) - 影子验证:kg/stats 数据连通(6.2s,与 7900 同源 normalized 后端) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
90 lines
2.6 KiB
Python
Executable File
90 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
激进版后处理 - 只保留高置信度关系
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
def aggressive_filter(input_path: str, output_path: str):
|
|
with open(input_path) as f:
|
|
data = json.load(f)
|
|
|
|
print("=" * 70)
|
|
print("Aggressive Post-Processing")
|
|
print("=" * 70)
|
|
|
|
original_rels = len(data.get('relations', []))
|
|
print(f"\nOriginal: {original_rels} relations")
|
|
|
|
# 只保留这些核心关系类型
|
|
core_types = {'member_of', 'classified_into', 'expressed_in', 'contains', 'involved_in'}
|
|
|
|
# 只保留这些核心实体参与的关系
|
|
core_entities = {'SPL', 'SBP', 'FtSPL1', 'FtSPL2', 'FtSPL3', 'FtSPL4',
|
|
'Group_I', 'Group_II', 'Group_VI', 'flower', 'fruit',
|
|
'flower_development', 'fruit_development'}
|
|
|
|
filtered = []
|
|
for r in data.get('relations', []):
|
|
rel_type = r.get('type') or r.get('relation', '')
|
|
source = r.get('source', '')
|
|
target = r.get('target', '')
|
|
|
|
# 规则1: 必须是核心类型
|
|
if rel_type not in core_types:
|
|
continue
|
|
|
|
# 规则2: 源实体必须是核心实体
|
|
if source not in core_entities:
|
|
continue
|
|
|
|
# 规则3: 删除明显错误
|
|
# 错误: SBP --member_of--> SPL
|
|
if rel_type == 'member_of' and source in ['SBP', 'ANK']:
|
|
continue
|
|
|
|
# 错误: SPL --belongs_to--> organism
|
|
if rel_type == 'belongs_to' and source == 'SPL':
|
|
continue
|
|
|
|
# 错误: gene --involved_in--> gene
|
|
if rel_type == 'involved_in' and target.startswith('FtSPL'):
|
|
continue
|
|
|
|
# 标准化字段
|
|
r['type'] = rel_type
|
|
if 'relation' in r:
|
|
del r['relation']
|
|
|
|
filtered.append(r)
|
|
|
|
data['relations'] = filtered
|
|
|
|
print(f"Filtered: {len(filtered)} relations (removed {original_rels - len(filtered)})")
|
|
|
|
print("\nKept relations:")
|
|
for r in filtered:
|
|
print(f" {r['source']} --{r['type']}--> {r['target']}")
|
|
|
|
with open(output_path, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
|
|
print(f"\n✓ Saved to: {output_path}")
|
|
|
|
# 对比
|
|
print("\n" + "=" * 70)
|
|
import subprocess
|
|
subprocess.run([
|
|
'python3', 'evaluation/compare_extraction.py',
|
|
'--gold', 'evaluation/gold_standard/pmid31286919_layer2_full.json',
|
|
'--pred', output_path
|
|
])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
aggressive_filter(
|
|
"evaluation/auto_results/pmid31286919_optimized_v3.json",
|
|
"evaluation/auto_results/pmid31286919_aggressive.json"
|
|
)
|