Dodanie zapisywania odpowiedzi

This commit is contained in:
Jakub Kaczmarek 2022-06-01 16:25:19 +02:00
parent c0aa726fd2
commit 0a1f6524e3
5 changed files with 44 additions and 19 deletions

View File

@ -3,7 +3,16 @@ class Dp:
self.act = act
self.param = param
self.answers = {
'request': {'imie': "welcomemsg"}
'request': {
'imie': "welcomemsg",
'from': "from",
'to': "to",
'time': "date",
'passangerCount': "travelers_count",
'discountCount': "travelers_discount_count",
'seatType': "seat_type",
'wagonType': "carrige_class",
}
}
def identify(self):

View File

@ -1,5 +1,5 @@
class Dst:
def __init__(self):
class Dst:
self.messages = []
self.checklist = {
"from": None,
@ -22,3 +22,9 @@ class Dst:
for key, value in self.checklist.items():
if value == None:
return key
def save_answer(self, slots):
for slot in slots:
self.checklist[slot[0]] = slot[1]
self.messages.append(slots)

View File

@ -1,14 +1,13 @@
import random
from urllib import response
from scipy import rand
class Nlg:
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)
def __init__(self) -> None:
self.responses = {
"welcomemsg": ["I AM TRAIlMinATor!", "Cześć, jestem TrailMinator"],
"null": ["Can't hear you"]}
def response(self, response_type: str) -> str:
avail_resps = self.responses.get(response_type)
return avail_resps[random.randint(0, len(avail_resps)-1)]

View File

@ -58,4 +58,4 @@ class Nlu:
return (act, param)
nlu = Nlu()
print(nlu.tokenize('chciałbym kupić bilet do Krakow'))
print(nlu.tokenize('chciałbym kupić bilet na pociąg z Poznan do Krakow'))

View File

@ -4,12 +4,23 @@ 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()}")
nlg = nlg.Nlg()
nlu = nlu.Nlu()
dst = dst.Dst()
d = dst.Dst()
print(d.get_next_question())
next_question = dst.get_next_question()
while (next_question):
print(next_question)
response = input()
res_tokenized = nlu.tokenize(response)
dst.save_answer(res_tokenized['slots'])
next_question = dst.get_next_question()
print(dst.checklist)
# print(dp_params)
# nlg_params = dp.Dp(*dp_params).identify()
# print(nlg_params)
#print(f"{msg}\n{nlg.Nlg(nlg_params).response()}")
#d = dst.Dst()
#print(d.get_next_question())