Nol00 commited on
Commit
2f4001e
·
verified ·
1 Parent(s): 835d6ca

Update src/model/crb_crs/recommender/movie_recommender.py

Browse files
src/model/crb_crs/recommender/movie_recommender.py CHANGED
@@ -535,18 +535,26 @@ class MovieRecommender(Recommender):
535
  movie_id: Movie ID.
536
 
537
  Raises:
538
- KeyError: if movie title cannot be found.
539
-
 
540
  Returns:
541
  Movie title.
542
  """
543
  try:
544
- title = self.movie_mentions_df.loc[[int(movie_id)]]["title"].iloc[
545
- 0
546
- ]
 
547
  except KeyError:
548
  title = ""
549
  logging.error(f"Movie title not found for movie ID {movie_id}.")
 
 
 
 
 
 
550
  return title
551
 
552
  def replace_item_ids_with_recommendations(
 
535
  movie_id: Movie ID.
536
 
537
  Raises:
538
+ KeyError: If the movie title is not found for the given movie ID.
539
+ Exception: If an error occurs when getting the movie title.
540
+
541
  Returns:
542
  Movie title.
543
  """
544
  try:
545
+ clean_movie_id = re.sub(r"\D", "", movie_id)
546
+ title = self.movie_mentions_df.loc[[int(clean_movie_id)]][
547
+ "title"
548
+ ].iloc[0]
549
  except KeyError:
550
  title = ""
551
  logging.error(f"Movie title not found for movie ID {movie_id}.")
552
+ except Exception as e:
553
+ title = ""
554
+ logging.error(
555
+ f"An error occurred when getting movie title for movie ID "
556
+ f"{movie_id}:\n{e}"
557
+ )
558
  return title
559
 
560
  def replace_item_ids_with_recommendations(