File size: 1,164 Bytes
1b377b0
c14838c
 
1b377b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re
from utils.utils import replace_regex
# from .utils import replace_regex

DEFAULT_MAP_DICT = {
    " c ": " c. ",
    ", chopped": " (chopped)",
    ", crumbled": " (crumbled)",
    ", thawed": " (thawed)",
    ", melted": " (melted)",
}


def ingredient(text, map_dict):
    if len(map_dict) > 0:
        map_dict.update(**DEFAULT_MAP_DICT)
    else:
        map_dict = DEFAULT_MAP_DICT

    text = replace_regex(text, map_dict)
    text = re.sub(r"(\d)\s(\d\/\d)", r" \1+\2 ", text)
    text = " ".join([word.strip() for word in text.split() if word.strip()])
    return text


def ingredients(text_list, item_list, without_mapping=False):
    map_dict = {
        item: f'<span class="text-bold">{item}</span>' for item in list(map(lambda x: x.lower().strip(), item_list))
    }
    text_list = list(map(lambda x: x.lower(), text_list))

    output = []
    for text in text_list:
        map_dict = map_dict if not without_mapping else {}
        text = ingredient(text, map_dict)
        output.append(text)

    return output


def directions(text_list):
    text_list = list(map(lambda x: x.lower().capitalize(), text_list))

    return text_list