File size: 977 Bytes
c8533a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re


class MessageParser:

    # =========================
    # DETECT VIDEO COUNT
    # =========================

    def extract_video_count(self, message):

        numbers = re.findall(r"\d+", message)

        if numbers:
            return int(numbers[0])

        text = message.lower()

        if "plusieurs" in text:
            return 5

        if "beaucoup" in text:
            return 10

        return 1

    # =========================
    # CLEAN THEME
    # =========================

    def extract_theme(self, message):

        text = message.lower()

        text = re.sub(r"cree|crée", "", text)
        text = re.sub(r"video|vidéo|videos|vidéos", "", text)
        text = re.sub(r"\d+", "", text)

        text = text.replace("sur", "")
        text = text.replace("plusieurs", "")
        text = text.replace("explique", "")

        text = text.strip()

        text = re.sub(r"^(le|la|les|un|une|des)\s+", "", text)

        return text