| 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 |