From 1cc1810886d1977cf05efea8c04646d97b3764ba Mon Sep 17 00:00:00 2001 From: MatOgr Date: Wed, 20 Apr 2022 11:25:16 +0200 Subject: [PATCH] Prototype implementation --- trailminator/dp.py | 14 +++++++++++++- trailminator/nlg.py | 14 +++++++++++++- trailminator/nlu.py | 2 -- trailminator/trailminator.py | 12 ++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 trailminator/trailminator.py diff --git a/trailminator/dp.py b/trailminator/dp.py index 475a1aa..742f6cc 100644 --- a/trailminator/dp.py +++ b/trailminator/dp.py @@ -1,2 +1,14 @@ class Dp: - pass \ No newline at end of file + def __init__(self, act, param): + self.act = act + self.param = param + self.answers = { + 'request': {'imie': "welcomemsg"} + } + + def identify(self): + req = self.answers.get(self.act) + response = req.get(self.param[0]) if not req is None else "null" + return response if not response is None else "null" + + \ No newline at end of file diff --git a/trailminator/nlg.py b/trailminator/nlg.py index eba938a..3c916a0 100644 --- a/trailminator/nlg.py +++ b/trailminator/nlg.py @@ -1,2 +1,14 @@ +import random +from urllib import response + +from scipy import rand + class Nlg: - pass \ No newline at end of file + def __init__(self, response_type: str) -> None: + self._response_type = response_type + self.responses = {"welcomemsg": ["I AM TRAIlMinATor!", "Cześć, jestem TrailMinator"], + "null": "Can't hear you"} + + def response(self) -> str: + avail_resps = self.responses.get(self._response_type) + return avail_resps[random.randint(0, len(avail_resps)-1)] \ No newline at end of file diff --git a/trailminator/nlu.py b/trailminator/nlu.py index d6ad913..328e020 100644 --- a/trailminator/nlu.py +++ b/trailminator/nlu.py @@ -42,5 +42,3 @@ class Nlu: return (act, param) -nlu = Nlu() -print(nlu.parse('jak masz na imie?')) \ No newline at end of file diff --git a/trailminator/trailminator.py b/trailminator/trailminator.py new file mode 100644 index 0000000..5cc2adc --- /dev/null +++ b/trailminator/trailminator.py @@ -0,0 +1,12 @@ +import dst +import nlu +import dp +import nlg + +if __name__ == "__main__": + msg = "Jak masz na imie?" + dp_params = nlu.Nlu().parse(msg) + # print(dp_params) + nlg_params = dp.Dp(*dp_params).identify() + # print(nlg_params) + print(f"{msg}\n{nlg.Nlg(nlg_params).response()}")