- 按生产 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>
101 lines
2.8 KiB
Python
Executable File
101 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
合并所有提取结果
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
def load_json(path):
|
|
with open(path) as f:
|
|
return json.load(f)
|
|
|
|
|
|
def save_json(data, path):
|
|
with open(path, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
|
|
|
|
def merge_extractions():
|
|
print("=" * 70)
|
|
print("Merging All Extractions")
|
|
print("=" * 70)
|
|
|
|
# 加载各个部分的结果
|
|
sources = [
|
|
('optimized_v3', 'evaluation/auto_results/pmid31286919_optimized_v3.json'),
|
|
('phylogeny', 'evaluation/auto_results/pmid31286919_phylogeny_mapped.json'),
|
|
]
|
|
|
|
merged = {
|
|
"metadata": {
|
|
"merged_from": [s[0] for s in sources],
|
|
"merge_time": "2026-03-28"
|
|
},
|
|
"entities": [],
|
|
"relations": []
|
|
}
|
|
|
|
seen_entities = set()
|
|
seen_relations = set()
|
|
|
|
for name, path in sources:
|
|
print(f"\nProcessing: {name}")
|
|
try:
|
|
data = load_json(path)
|
|
|
|
# 合并实体
|
|
for e in data.get('entities', []):
|
|
eid = e.get('id', '')
|
|
if eid and eid not in seen_entities:
|
|
seen_entities.add(eid)
|
|
e['source'] = name
|
|
merged['entities'].append(e)
|
|
|
|
# 合并关系
|
|
for r in data.get('relations', []):
|
|
rel_type = r.get('type') or r.get('relation', '')
|
|
key = (r.get('source', ''), rel_type, r.get('target', ''))
|
|
if key not in seen_relations:
|
|
seen_relations.add(key)
|
|
r['source_file'] = name
|
|
merged['relations'].append(r)
|
|
|
|
print(f" Entities: {len(data.get('entities', []))}")
|
|
print(f" Relations: {len(data.get('relations', []))}")
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
|
|
print(f"\n" + "=" * 70)
|
|
print("Merged Results:")
|
|
print("=" * 70)
|
|
print(f" Total entities: {len(merged['entities'])}")
|
|
print(f" Total relations: {len(merged['relations'])}")
|
|
|
|
# 统计关系类型
|
|
from collections import Counter
|
|
rel_types = Counter(r.get('type') or r.get('relation', '') for r in merged['relations'])
|
|
print(f"\n Relation types:")
|
|
for t, c in rel_types.most_common():
|
|
print(f" {t}: {c}")
|
|
|
|
# 保存
|
|
output_path = 'evaluation/auto_results/pmid31286919_merged_final.json'
|
|
save_json(merged, output_path)
|
|
print(f"\n✓ Saved to: {output_path}")
|
|
|
|
# 对比 Gold Standard
|
|
print("\n" + "=" * 70)
|
|
print("Comparison with Layer 2 Full")
|
|
print("=" * 70)
|
|
import subprocess
|
|
subprocess.run([
|
|
'python3', 'evaluation/compare_extraction.py',
|
|
'--gold', 'evaluation/gold_standard/pmid31286919_layer2_full.json',
|
|
'--pred', output_path
|
|
])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
merge_extractions()
|