trailminator #1

Merged
s434624 merged 6 commits from trailminator into master 2022-05-18 12:39:33 +02:00
4 changed files with 59 additions and 0 deletions
Showing only changes of commit 6700154e86 - Show all commits

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?'))