forked from matterport/Mask_RCNN
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecommend.py
More file actions
37 lines (31 loc) · 1.05 KB
/
recommend.py
File metadata and controls
37 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import difflib
import os
ROOT_DIR = os.getcwd()
DATA_DIR = os.path.join(ROOT_DIR, "logs/data/recipes.json")
def load_json(file):
with open(file) as json_file:
data = json.load(json_file)
return data
def get_title_list(recipe):
title_list = []
for i in range(0, len(recipe)):
title_list.append("{} {}".format(recipe['{}'.format(i)]['title'].lower(), recipe['{}'.format(i)]['id']))
return title_list
def get_recommendation(food, title_list):
find_close_match = difflib.get_close_matches(food, title_list, n=10, cutoff=0.4)
list_id = []
for item in find_close_match:
word = item.split()
list_id.append(word[-1])
return list_id
def get_result(food):
result = []
recipe = load_json(DATA_DIR)
title_list = get_title_list(recipe)
recommendation = get_recommendation(food, title_list)
for item in recommendation:
for i in range(0, len(recipe)):
if str(recipe["{}".format(i)]['id']) == item:
result.append(recipe["{}".format(i)])
return result