71 lines
2.1 KiB
Python
Executable File
71 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from src.rag.extractors.v16_1_2.paper_metadata_enricher_v16_1_2 import (
|
|
PaperMetadataEnricherV16,
|
|
)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Add canonical DOI/PMID/PMCID and citation metadata to a V16 result.json."
|
|
)
|
|
parser.add_argument("--result-json", required=True, type=Path)
|
|
parser.add_argument("--pdf", type=Path)
|
|
parser.add_argument("--doi", default="")
|
|
parser.add_argument("--pmid", default="")
|
|
parser.add_argument("--pmcid", default="")
|
|
parser.add_argument("--output", type=Path)
|
|
parser.add_argument("--in-place", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
source = args.result_json.resolve()
|
|
if not source.exists():
|
|
raise SystemExit(f"Missing result JSON: {source}")
|
|
if not args.in_place and not args.output:
|
|
raise SystemExit("Use --in-place or provide --output.")
|
|
destination = source if args.in_place else args.output.resolve()
|
|
|
|
data = json.loads(source.read_text(encoding="utf-8"))
|
|
enricher = PaperMetadataEnricherV16()
|
|
paper = enricher.resolve(
|
|
pdf_path=args.pdf.resolve() if args.pdf else None,
|
|
doi=args.doi,
|
|
pmid=args.pmid,
|
|
pmcid=args.pmcid,
|
|
)
|
|
enricher.enrich_output(data, paper)
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.write_text(
|
|
json.dumps(data, ensure_ascii=False, indent=2),
|
|
encoding="utf-8",
|
|
)
|
|
audit_path = destination.parent / "paper_metadata_enrichment_audit.json"
|
|
enricher.save_audit(audit_path, paper)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"result_json": str(destination),
|
|
"audit": str(audit_path),
|
|
"paper": paper,
|
|
"relations": len(data.get("relations", [])),
|
|
},
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|