Add trailminator to the party
This commit is contained in:
parent
e5a627f959
commit
6700154e86
2
trailminator/dp.py
Normal file
2
trailminator/dp.py
Normal file
@ -0,0 +1,2 @@
|
||||
class Dp:
|
||||
pass
|
9
trailminator/dst.py
Normal file
9
trailminator/dst.py
Normal 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
2
trailminator/nlg.py
Normal file
@ -0,0 +1,2 @@
|
||||
class Nlg:
|
||||
pass
|
46
trailminator/nlu.py
Normal file
46
trailminator/nlu.py
Normal 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?'))
|
Loading…
Reference in New Issue
Block a user