Catch and logging
This commit is contained in:
parent
7f79eb1e26
commit
b48c59b377
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import logging
|
||||||
from fuzzywuzzy import fuzz, process
|
from fuzzywuzzy import fuzz, process
|
||||||
from .AlgorithmBase import AlgorithmBase, MatchResult
|
from .AlgorithmBase import AlgorithmBase, MatchResult
|
||||||
from clazz.Metadata import Metadata
|
from clazz.Metadata import Metadata
|
||||||
@ -10,23 +11,29 @@ class SimpleMatcher(AlgorithmBase):
|
|||||||
best_score = -1
|
best_score = -1
|
||||||
match_results = []
|
match_results = []
|
||||||
|
|
||||||
for title in self.titles:
|
try:
|
||||||
for metadata in self.metadata:
|
for title in self.titles:
|
||||||
# Match against metadata title
|
for metadata in self.metadata:
|
||||||
score = fuzz.token_sort_ratio(title.lower(), metadata.title.lower())
|
# Match against metadata title
|
||||||
match_results.append(MatchResult(title, metadata.title, score, metadata.source, metadata))
|
score = fuzz.token_sort_ratio(title.lower(), metadata.title.lower())
|
||||||
if score > best_score:
|
match_results.append(MatchResult(title, metadata.title, score, metadata.source, metadata))
|
||||||
best_score = score
|
if score > best_score:
|
||||||
best_match = metadata if score >= 70 else None
|
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
|
|
||||||
|
|
||||||
|
# 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
|
# Print match summary
|
||||||
self.print_match_summary(match_results)
|
self.print_match_summary(match_results)
|
||||||
|
|
||||||
|
|||||||
@ -55,9 +55,17 @@ class UseSource:
|
|||||||
|
|
||||||
highScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(wd.result.title.lower()))
|
highScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(wd.result.title.lower()))
|
||||||
for alt_title in wd.result.altTitle:
|
for alt_title in wd.result.altTitle:
|
||||||
altScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(alt_title.lower()))
|
try:
|
||||||
if altScore > highScore:
|
altScore = fuzz.ratio(self.stripped(title_to_check.lower()), self.stripped(alt_title.lower()))
|
||||||
highScore = altScore
|
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
|
givenScore = highScore * wd.weight
|
||||||
result.append(DataAndScore(wd.result, givenScore, wd.weight, title_to_check))
|
result.append(DataAndScore(wd.result, givenScore, wd.weight, title_to_check))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user