43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
"""메타데이터 추출 F1 평가 단위테스트 (성능지표 No.3)."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.engine.metadata_eval import set_prf, evaluate_extraction
|
|
|
|
|
|
def test_set_prf_perfect():
|
|
r = set_prf(["홍길동", "활빈당"], ["홍길동", "활빈당"])
|
|
assert r.f1 == 1.0 and r.fp == 0 and r.fn == 0
|
|
|
|
|
|
def test_set_prf_partial():
|
|
r = set_prf(["홍길동", "임꺽정"], ["홍길동", "활빈당"])
|
|
assert r.tp == 1 and r.fp == 1 and r.fn == 1
|
|
assert 0.0 < r.f1 < 1.0
|
|
|
|
|
|
def test_set_prf_case_insensitive():
|
|
r = set_prf(["Hong"], ["hong"])
|
|
assert r.f1 == 1.0
|
|
|
|
|
|
def test_evaluate_extraction_micro():
|
|
preds = [{"characters": ["홍길동"], "motifs": ["복수"], "keywords": ["활빈당"], "genre": "역사"}]
|
|
golds = [{"characters": ["홍길동"], "motifs": ["복수"], "keywords": ["활빈당"], "genre": "역사"}]
|
|
out = evaluate_extraction(preds, golds)
|
|
assert out["micro_avg"]["f1"] == 1.0
|
|
assert out["genre_accuracy"]["accuracy"] == 1.0
|
|
|
|
|
|
def test_evaluate_extraction_genre_mismatch():
|
|
preds = [{"characters": [], "motifs": [], "keywords": [], "genre": "SF"}]
|
|
golds = [{"characters": [], "motifs": [], "keywords": [], "genre": "역사"}]
|
|
out = evaluate_extraction(preds, golds)
|
|
assert out["genre_accuracy"]["accuracy"] == 0.0
|
|
|
|
|
|
def test_length_mismatch_raises():
|
|
with pytest.raises(ValueError):
|
|
evaluate_extraction([{}], [{}, {}])
|