File size: 980 Bytes
3f4ebee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/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()
|