Catch and logging

This commit is contained in:
Brage Skjønborg 2025-07-06 00:15:09 +02:00
parent 7f79eb1e26
commit b48c59b377
2 changed files with 34 additions and 19 deletions

View File

@ -1,4 +1,5 @@
import logging
from fuzzywuzzy import fuzz, process
from .AlgorithmBase import AlgorithmBase, MatchResult
from clazz.Metadata import Metadata
@ -10,23 +11,29 @@ class SimpleMatcher(AlgorithmBase):
best_score = -1
match_results = []
for title in self.titles:
for metadata in self.metadata:
# Match against metadata title
score = fuzz.token_sort_ratio(title.lower(), metadata.title.lower())
match_results.append(MatchResult(title, metadata.title, score, metadata.source, metadata))
if score > best_score:
best_score = score
best_match = metadata if score >= 70 else None
# Match against metadata altTitles
for alt_title in metadata.altTitle:
alt_score = fuzz.token_sort_ratio(title.lower(), alt_title.lower())
match_results.append(MatchResult(title, alt_title, alt_score, metadata.source, metadata))
if alt_score > best_score:
best_score = alt_score
best_match = metadata if alt_score >= 70 else None
try:
for title in self.titles:
for metadata in self.metadata:
# Match against metadata title
score = fuzz.token_sort_ratio(title.lower(), metadata.title.lower())
match_results.append(MatchResult(title, metadata.title, score, metadata.source, metadata))
if score > best_score:
best_score = score
best_match = metadata if score >= 70 else None
# Match against metadata altTitles
for alt_title in metadata.altTitle:
alt_score = fuzz.token_sort_ratio(title.lower(), alt_title.lower())
match_results.append(MatchResult(title, alt_title, alt_score, metadata.source, metadata))
if alt_score > best_score:
best_score = alt_score
best_match = metadata if alt_score >= 70 else None
except Exception as e:
logging.debug("Unntak: {e}")
logging.debug(f"type(title): {type(title)}, value: {title}")
logging.debug(f"type(alt_title): {type(alt_title)}, value: {alt_title}")
logging.debug(f"Metadata objekt:")
logging.debug(metadata.to_dict())
# Print match summary
self.print_match_summary(match_results)

View File

@ -55,9 +55,17 @@ class UseSource:
highScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(wd.result.title.lower()))
for alt_title in wd.result.altTitle:
altScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(alt_title.lower()))
if altScore > highScore:
highScore = altScore
try:
altScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(alt_title.lower()))
if altScore > highScore:
highScore = altScore
except Exception as e:
logging.debug("Unntak: {e}")
logging.debug(f"type(title): {type(title)}, value: {title}")
logging.debug(f"type(alt_title): {type(alt_title)}, value: {alt_title}")
logging.debug(f"Metadata objekt:")
logging.debug(weightData)
givenScore = highScore * wd.weight
result.append(DataAndScore(wd.result, givenScore, wd.weight, title_to_check))