import logging from services.similarity import cosine_lists logger = logging.getLogger(__name__) class Headline: display_text: str normalized_text: list[str] def __init__(self, display_text: str, normalized_text: list[str]): self.display_text = display_text self.normalized_text = normalized_text logger.debug("Initialized Headline instance (display_text=%r, token_count=%d): %s", self.display_text, len(self.normalized_text), self.normalized_text) def compare_headlines(self, other_headline): if not isinstance(other_headline, Headline): logger.warning("Comparing Headline %r with incompatible object of type %s: %r", self.display_text, type(other_headline).__name__, other_headline) logger.debug("Comparing Headline %r against %r", self.display_text, getattr(other_headline, 'display_text', repr(other_headline))) try: score = cosine_lists(self.normalized_text, other_headline.normalized_text) logger.debug("Headline comparison score: %.4f between %r and %r", score, self.display_text, getattr(other_headline, 'display_text', repr(other_headline))) return score except Exception as e: logger.error("Error comparing headlines (%r vs %r): %s", self.display_text, getattr(other_headline, 'display_text', repr(other_headline)), e, exc_info=True) raise