Exemple #1
0
def recommend(dish_id: int, recommendation_count: int = 5) -> Optional[dict]:
    """Recommends similar dishes.
    Args:
      dish_id (int): Dish id which koolsla recommends similar ones.
      recommendation_count (int): Max recommendation count given by user.
    Returns:
      indice, similarity value (dictionary): Indice & similarity value or None.
    """

    is_valid = data.validate_dish_id(dish_id)
    if is_valid:
        # Import the data
        imported_data = data.import_data()
        # Get the metadatasets
        dataset = data.split_data(imported_data)
        # Train the recommendation engine
        tfidf_matrix = tfidf.train_engine(dataset['names'])
        # Generate recommendations
        recomended_dishes = tfidf.find_similarities(tfidf_matrix, dish_id, recommendation_count)
        # Input dish
        color_print.print_green('Given Dish')
        color_print.print_dish(
                    name=dataset['names'][dish_id],
                    dish_id=dish_id,
                    color=color_print.green)
        # Display the recommended dishes
        color_print.print_yellow('Top ' + str(recommendation_count) + ' Recommendations')
        for i, _ in recomended_dishes:
            color_print.print_green(i)
            color_print.print_dish(
                    name=dataset['names'][i],
                    dish_id=i,
                    color=color_print.yellow)
        return recomended_dishes
    return None
Exemple #2
0
 def test_import_data(self):
     dish_dataset = data.import_data(data.dish_dataset_path)
     self.assertEqual(len(dish_dataset), 424509)
Exemple #3
0
 def test_split_data(self):
     dish_dataset = data.import_data(data.dish_dataset_path)
     split_data = data.split_data(dish_dataset)
     self.assertIsNotNone(split_data)
Exemple #4
0
 def test_train_engine(self):
     dish_dataset = data.import_data(data.dish_dataset_path)
     split_data = data.split_data(dish_dataset)
     tfidf_matrix = tfidf.train_engine(split_data['names'])
     self.assertIsNotNone(tfidf_matrix)
Exemple #5
0
 def test_find_similarities(self):
     dish_dataset = data.import_data(data.dish_dataset_path)
     split_data = data.split_data(dish_dataset)
     tfidf_matrix = tfidf.train_engine(split_data['names'])
     similar_dishes = tfidf.find_similarities(tfidf_matrix, 25, 5)
     self.assertIsNotNone(similar_dishes)