- 按生产 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>
108 lines
3.1 KiB
Python
Executable File
108 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
最终合并 v2 - 包含所有章节
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
|
|
|
|
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 main():
|
|
print("=" * 70)
|
|
print("Final Merge v2 - All Sections")
|
|
print("=" * 70)
|
|
|
|
# 加载所有结果
|
|
sources = [
|
|
('optimized_v3', 'evaluation/auto_results/pmid31286919_optimized_v3.json'),
|
|
('phylogeny', 'evaluation/auto_results/pmid31286919_phylogeny_mapped.json'),
|
|
('expression', 'evaluation/auto_results/pmid31286919_expression_v2.json'),
|
|
('methods', 'evaluation/auto_results/pmid31286919_methods_v2.json'),
|
|
]
|
|
|
|
merged = {
|
|
"metadata": {
|
|
"merged_from": [s[0] for s in sources],
|
|
"description": "Final merged with all sections"
|
|
},
|
|
"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)
|
|
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)
|
|
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("Final Results:")
|
|
print("=" * 70)
|
|
print(f" Total entities: {len(merged['entities'])}")
|
|
print(f" Total relations: {len(merged['relations'])}")
|
|
|
|
# 统计
|
|
from collections import Counter
|
|
entity_types = Counter(e.get('type', 'unknown') for e in merged['entities'])
|
|
rel_types = Counter(r.get('type') or r.get('relation', '') for r in merged['relations'])
|
|
|
|
print(f"\n Entity types:")
|
|
for t, c in entity_types.most_common():
|
|
print(f" {t}: {c}")
|
|
|
|
print(f"\n Relation types:")
|
|
for t, c in rel_types.most_common():
|
|
print(f" {t}: {c}")
|
|
|
|
# 保存
|
|
output_path = 'evaluation/auto_results/pmid31286919_final_v2.json'
|
|
save_json(merged, output_path)
|
|
print(f"\n✓ Saved to: {output_path}")
|
|
|
|
# 评估
|
|
print("\n" + "=" * 70)
|
|
print("FINAL EVALUATION")
|
|
print("=" * 70)
|
|
result = subprocess.run([
|
|
'python3', 'evaluation/compare_extraction.py',
|
|
'--gold', 'evaluation/gold_standard/pmid31286919_layer2_full.json',
|
|
'--pred', output_path
|
|
], capture_output=True, text=True)
|
|
print(result.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|