feat: add confidence scoring
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from lyra_worker.confidence import score_confidence
|
||||
from lyra_worker.types import Candidate, MBTarget, Quality
|
||||
|
||||
Q = Quality(fmt="FLAC", lossless=True, bit_depth=16, sample_rate=44100)
|
||||
|
||||
|
||||
def _cand(artist, album, tracks=10):
|
||||
return Candidate(source="qobuz", source_ref="x", matched_artist=artist,
|
||||
matched_album=album, quality=Q, track_count=tracks)
|
||||
|
||||
|
||||
def test_exact_match_scores_high():
|
||||
target = MBTarget(artist="Radiohead", album="In Rainbows", track_count=10)
|
||||
assert score_confidence(target, _cand("Radiohead", "In Rainbows", 10)) > 0.95
|
||||
|
||||
|
||||
def test_case_and_whitespace_insensitive():
|
||||
target = MBTarget(artist="Radiohead", album="In Rainbows")
|
||||
assert score_confidence(target, _cand(" radiohead ", "IN RAINBOWS")) > 0.95
|
||||
|
||||
|
||||
def test_wrong_album_scores_low():
|
||||
target = MBTarget(artist="Radiohead", album="In Rainbows", track_count=10)
|
||||
assert score_confidence(target, _cand("Radiohead", "OK Computer", 12)) < 0.7
|
||||
|
||||
|
||||
def test_unknown_track_count_does_not_penalize():
|
||||
target = MBTarget(artist="Radiohead", album="In Rainbows", track_count=None)
|
||||
# track_count unknown -> track_factor neutral; name match still drives a high score
|
||||
assert score_confidence(target, _cand("Radiohead", "In Rainbows", 99)) > 0.95
|
||||
|
||||
|
||||
def test_track_count_mismatch_lowers_score():
|
||||
target = MBTarget(artist="Radiohead", album="In Rainbows", track_count=10)
|
||||
good = score_confidence(target, _cand("Radiohead", "In Rainbows", 10))
|
||||
bad = score_confidence(target, _cand("Radiohead", "In Rainbows", 4))
|
||||
assert bad < good
|
||||
Reference in New Issue
Block a user