sklep-internetowy-systemy-d.../chatbot/modules/nlp.py
2024-05-07 23:34:34 +02:00

23 lines
637 B
Python

import json
import re
from typing import Dict, List, TypedDict
from .config import Config
class Intents(TypedDict):
ask_name: List[str]
class NaturalLanguageProcessor:
def __init__(self, config: Config):
with config.data_path.open('r', encoding='utf-8') as file:
self.intents: Dict[str, List[str]] = json.load(file)
def analyze(self, input_text: str) -> str:
input_text = input_text.lower()
for intent, patterns in self.intents.items():
for pattern in patterns:
if re.search(pattern, input_text):
return intent
return "unknown"