From b48c59b3770064b23992654428fb4139b678864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brage=20Skj=C3=B8nborg?= Date: Sun, 6 Jul 2025 00:15:09 +0200 Subject: [PATCH] Catch and logging --- apps/pyMetadata/algo/SimpleMatcher.py | 39 +++++++++++++++----------- apps/pyMetadata/algo/SourceWeighted.py | 14 +++++++-- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/apps/pyMetadata/algo/SimpleMatcher.py b/apps/pyMetadata/algo/SimpleMatcher.py index f9da2db2..01c07a68 100644 --- a/apps/pyMetadata/algo/SimpleMatcher.py +++ b/apps/pyMetadata/algo/SimpleMatcher.py @@ -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) diff --git a/apps/pyMetadata/algo/SourceWeighted.py b/apps/pyMetadata/algo/SourceWeighted.py index 0bb730d6..223fe2f0 100644 --- a/apps/pyMetadata/algo/SourceWeighted.py +++ b/apps/pyMetadata/algo/SourceWeighted.py @@ -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))