-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
75 lines (59 loc) · 1.91 KB
/
main.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from recipeFetcher import RecipeFetcher
from word_transformations import Transformer
from nlp_common import WordTagger
from displayResults import DisplayResults
import user_prompts
def run_nlp(recipe):
"""Takes recipe array and returns nlp processed results
:param recipe:
:return:
"""
tagger = WordTagger()
tagger.process_ingredients(recipe)
tagger.process_tools(recipe)
tagger.process_recipe_methods(recipe)
tagger.process_directions(recipe)
return {
'ingredients': tagger.found_ingredients,
'tools': tagger.found_tools,
'methods': tagger.found_methods,
'directions': tagger.found_directions
}
def get_recipe():
"""prompts a user for a url, searches and parses a recipe and returns dict representation of a recipe.
:return: {}, recipe json
"""
rf = RecipeFetcher()
recipe_url = user_prompts.search_url_input()
return rf.scrape_recipe(recipe_url)
def transform_recipe(recipe):
"""prompt and perform transformations on a recipe using the transformation mapping in the class
:param recipe: recipe to perform transformations on
:return: {}, new recipe
"""
transformer = Transformer()
user_prompts.set_transformations()
trans_option = user_prompts.transformation()
transformed_recipe = transformer.transformation_mapping[trans_option](recipe)
return transformed_recipe
def main():
recipe = get_recipe()
nlp_recipe_results = run_nlp(recipe)
printer = DisplayResults(results=nlp_recipe_results)
printer.print_all()
# transformation recipe
while True:
recipe = transform_recipe(recipe)
transformed_nlp_results = run_nlp(recipe)
printer = DisplayResults(results=transformed_nlp_results)
printer.print_all()
user_prompts.continue_startover()
selected_option = user_prompts.next_step()
if selected_option == 1:
continue
elif selected_option == 2:
return main()
else:
return
if __name__ == '__main__':
main()