No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

headline.py 1.5 KiB

hace 4 días
1234567891011121314151617181920212223242526272829303132
  1. import logging
  2. from services.similarity import cosine_lists
  3. logger = logging.getLogger(__name__)
  4. class Headline:
  5. display_text: str
  6. normalized_text: list[str]
  7. def __init__(self, display_text: str, normalized_text: list[str]):
  8. self.display_text = display_text
  9. self.normalized_text = normalized_text
  10. logger.debug("Initialized Headline instance (display_text=%r, token_count=%d): %s",
  11. self.display_text, len(self.normalized_text), self.normalized_text)
  12. def compare_headlines(self, other_headline):
  13. if not isinstance(other_headline, Headline):
  14. logger.warning("Comparing Headline %r with incompatible object of type %s: %r",
  15. self.display_text, type(other_headline).__name__, other_headline)
  16. logger.debug("Comparing Headline %r against %r",
  17. self.display_text, getattr(other_headline, 'display_text', repr(other_headline)))
  18. try:
  19. score = cosine_lists(self.normalized_text, other_headline.normalized_text)
  20. logger.debug("Headline comparison score: %.4f between %r and %r",
  21. score, self.display_text, getattr(other_headline, 'display_text', repr(other_headline)))
  22. return score
  23. except Exception as e:
  24. logger.error("Error comparing headlines (%r vs %r): %s",
  25. self.display_text, getattr(other_headline, 'display_text', repr(other_headline)), e, exc_info=True)
  26. raise