#!/usr/bin/env python3 from __future__ import annotations import argparse import json from pathlib import Path from literature.evaluation import evaluate_predictions, load_json_records def main() -> None: parser = argparse.ArgumentParser(description="Evaluate extraction output against a POLYIE-style gold file.") parser.add_argument("--gold", required=True, help="Gold file (.json or .jsonl)") parser.add_argument("--pred", required=True, help="Prediction file (.json or .jsonl)") parser.add_argument("--out", default=None, help="Optional JSON output path") args = parser.parse_args() gold_records = load_json_records(args.gold) predicted_records = load_json_records(args.pred) metrics = evaluate_predictions(gold_records, predicted_records) text = json.dumps(metrics, indent=2, ensure_ascii=False) print(text) if args.out: Path(args.out).write_text(text + "\n", encoding="utf-8") if __name__ == "__main__": main()