Add trailminator to the party

This commit is contained in:
Jakub Kaczmarek 2022-04-13 13:23:47 +02:00
parent e5a627f959
commit 6700154e86
4 changed files with 59 additions and 0 deletions

2
trailminator/dp.py Normal file
View File

@ -0,0 +1,2 @@
class Dp:
pass

9
trailminator/dst.py Normal file
View File

@ -0,0 +1,9 @@
class Dst:
def __init__(self):
self.messages = []
def store(self, message):
self.messages.append(message)
def get_messages(self):
return self.messages

2
trailminator/nlg.py Normal file
View File

@ -0,0 +1,2 @@
class Nlg:
pass

46
trailminator/nlu.py Normal file
View File

@ -0,0 +1,46 @@
import re
class Nlu:
def __init__(self):
self.acts = {
"request": {
'triggers': ['jak', 'kiedy'],
'parameters': ['imie']
}
}
def tokenize(self, string):
clean_string = self.get_str_cleaned(string)
return clean_string.split()
def get_str_cleaned(self, str_dirty):
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\\\]^_`{|}~'
new_str = str_dirty.lower()
new_str = re.sub(' +', ' ', new_str)
for char in punctuation:
new_str = new_str.replace(char,'')
return new_str
def parse(self, message):
tokens = self.tokenize(message)
act = None
param = []
for k, v in self.acts.items():
if any(t in v['triggers'] for t in tokens):
act = k
for t in tokens:
if t in v['parameters']:
param.append(t)
return (act, param)
nlu = Nlu()
print(nlu.parse('jak masz na imie?'))