From 6700154e860bbe127cd4afdddf0444e04a4bf5bd Mon Sep 17 00:00:00 2001 From: Jakub Kaczmarek Date: Wed, 13 Apr 2022 13:23:47 +0200 Subject: [PATCH] Add trailminator to the party --- trailminator/dp.py | 2 ++ trailminator/dst.py | 9 +++++++++ trailminator/nlg.py | 2 ++ trailminator/nlu.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 trailminator/dp.py create mode 100644 trailminator/dst.py create mode 100644 trailminator/nlg.py create mode 100644 trailminator/nlu.py diff --git a/trailminator/dp.py b/trailminator/dp.py new file mode 100644 index 0000000..475a1aa --- /dev/null +++ b/trailminator/dp.py @@ -0,0 +1,2 @@ +class Dp: + pass \ No newline at end of file diff --git a/trailminator/dst.py b/trailminator/dst.py new file mode 100644 index 0000000..8bbf494 --- /dev/null +++ b/trailminator/dst.py @@ -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 diff --git a/trailminator/nlg.py b/trailminator/nlg.py new file mode 100644 index 0000000..eba938a --- /dev/null +++ b/trailminator/nlg.py @@ -0,0 +1,2 @@ +class Nlg: + pass \ No newline at end of file diff --git a/trailminator/nlu.py b/trailminator/nlu.py new file mode 100644 index 0000000..d6ad913 --- /dev/null +++ b/trailminator/nlu.py @@ -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?')) \ No newline at end of file