This commit is contained in:
Anna Nowak 2021-06-07 09:30:35 +02:00
parent f201155d1a
commit 39bdbe4cdb
4 changed files with 73 additions and 32 deletions

View File

@ -12,7 +12,7 @@ class DP():
def predict(self, state): def predict(self, state):
self.results = [] self.results = []
system_action = defaultdict(list) system_action = defaultdict(dict)
user_action = defaultdict(list) user_action = defaultdict(list)
system_acts = [] system_acts = []
while len(state['user_action']) > 0: while len(state['user_action']) > 0:
@ -47,14 +47,14 @@ class DP():
elif intent == 'appointment/create_appointment': elif intent == 'appointment/create_appointment':
for x in constraints: for x in constraints:
if(x[0] == 'doctor'): if(x[0] == 'doctor'):
system_action[(domain, 'book_appointent')].append([x[0], x[1]]) system_action[(domain, 'book_appointent')][x[0]] = x[1]
for y in constraints: for y in constraints:
if(y[0] == 'datetime'): if(y[0] == 'datetime'):
system_action[(domain, 'book_appointent')].append([y[0], y[1]]) system_action[(domain, 'book_appointent')][y[0]] = y[1]
elif intent == 'appointment/set_date': elif intent == 'appointment/set_date':
for y in constraints: for y in constraints:
if(y[0] == 'datetime'): if(y[0] == 'datetime'):
system_action[(domain, 'set_appointment_date')].append([y[0], y[1]]) system_action[(domain, 'set_appointment_date')][y[0]] = y[1]
@ -66,10 +66,10 @@ class DP():
if intent == 'request_information/available_dates': if intent == 'request_information/available_dates':
for x in constraints_v2: for x in constraints_v2:
if(x[0] == 'doctor'): if(x[0] == 'doctor'):
system_action[(domain, 'date_info')].append([x[0], x[1]]) system_action[(domain, 'date_info')][x[0]] = x[1]
for y in constraints_v2: for y in constraints_v2:
if(y[0] == 'datetime'): if(y[0] == 'datetime'):
system_action[(domain, 'date_info')].append([y[0], y[1]]) system_action[(domain, 'date_info')][y[0]] = y[1]
elif intent == 'request_information/doctors': elif intent == 'request_information/doctors':
system_action[("inform", 'Doctors_list')] = {"doctors": "dr. Kolano - okulista, dr. Kowalski - internista, dr. Kaszak - ginekolog"} system_action[("inform", 'Doctors_list')] = {"doctors": "dr. Kolano - okulista, dr. Kowalski - internista, dr. Kaszak - ginekolog"}
elif intent == 'request_information/location': elif intent == 'request_information/location':
@ -77,19 +77,19 @@ class DP():
elif intent == 'request_information/cost': elif intent == 'request_information/cost':
system_action[("inform", 'Cost')] = {"cost": "100 zł"} system_action[("inform", 'Cost')] = {"cost": "100 zł"}
elif intent == 'request_information/opening_hours': elif intent == 'request_information/opening_hours':
system_action[("inform", 'Opening_Hours')] = ["hours", ['8:00 - 16:00']] system_action[("inform", 'Opening_Hours')] = {"hours": "'8:00 - 16:00"}
elif len(constraints) == 0: elif len(constraints) == 0:
system_action[("inform", 'NoOffer')] = [] system_action[("inform", 'NoOffer')] = {'0': '0'}
################################################################################################# #################################################################################################
# Reguła 3 # Reguła 3
if domain == 'end_conversation': if domain == 'end_conversation':
system_action[(domain, 'End_Conversation')] = ['0', '0'] system_action[(domain, 'End_Conversation')] = {'0': '0'}
################################################################################################# #################################################################################################
# Reguła 4 # Reguła 4
if domain == 'greeting': if domain == 'greeting':
system_action[(domain, 'Greeting')] = ['0', '0'] system_action[(domain, 'Greeting')] = {'0': '0'}
################################################################################################# #################################################################################################
# Reguła 5 # Reguła 5
@ -98,18 +98,18 @@ class DP():
if intent == 'prescription/request': if intent == 'prescription/request':
for x in constraints_v2: for x in constraints_v2:
if(x[0] == 'prescription/type'): if(x[0] == 'prescription/type'):
system_action[(domain, 'create_prescription')].append([x[0], x[1]]) system_action[(domain, 'create_prescription')][x[0]] = x[1]
for y in constraints_v2: for y in constraints_v2:
if(y[0] == 'prescription/medicine'): if(y[0] == 'prescription/medicine'):
system_action[(domain, 'create_prescription')].append([y[0], y[1]]) system_action[(domain, 'create_prescription')][y[0]] = y[1]
elif intent == 'prescription/collect': elif intent == 'prescription/collect':
for x in constraints_v2: for x in constraints_v2:
if(x[0] == 'prescription/type'): if(x[0] == 'prescription/type'):
system_action[(domain, 'collect_prescription')].append([x[0], x[1]]) system_action[(domain, 'collect_prescription')][x[0]] = x[1]
elif intent == 'prescription/type': elif intent == 'prescription/type':
for x in constraints_v2: for x in constraints_v2:
if(x[0] == 'prescription/type_info'): if(x[0] == 'prescription/type_info'):
system_action[(domain, 'prescription type')].append([x[0], x[1]]) system_action[(domain, 'prescription type')][x[0]] = x[1]
if len(constraints_v2) == 0: if len(constraints_v2) == 0:
system_action[(domain, 'NoOffer')] = [] system_action[(domain, 'NoOffer')] = []

View File

@ -28,6 +28,18 @@ class Rules_DST(): #Dialogue State Tracker
if slot in domain_dic: if slot in domain_dic:
self.state['belief_state'][domain][slot] = value self.state['belief_state'][domain][slot] = value
if 'prescription' in intent:
if (slot == 'prescription'):
continue
if(domain in slot):
slot.replace(domain + "/", '')
if domain not in self.state['request_state']:
self.state['request_state'][domain] = {}
if slot not in self.state['request_state'][domain]:
self.state['request_state'][domain][slot] = value
if 'request_information' in intent: if 'request_information' in intent:
if (slot == 'request_information'): if (slot == 'request_information'):
continue continue
@ -42,6 +54,6 @@ class Rules_DST(): #Dialogue State Tracker
elif intent == 'end_conversation': elif intent == 'end_conversation':
self.state = json.load(open('default_state.json')) self.state = json.load(open('default_state.json'))
print(self.state) # print(self.state)
print("\n") # print("\n")
return self.state return self.state

View File

@ -1,4 +1,5 @@
import random import random
import uuid
class NLG: class NLG:
""" """
@ -22,11 +23,8 @@ class NLG:
if(len(act) == 0): if(len(act) == 0):
return "Nie mam już nic do powiedzenia :(" return "Nie mam już nic do powiedzenia :("
domain, intent = act[0] for action in act:
domain, intent = action
if (domain == "inform"):
return "test"
if(domain == "greeting"): if(domain == "greeting"):
return random.choice(["Cześć, mam na imię Janet", "Hej, jestem Janet. W czym mogę pomóc?", "Dzień dobry, nazywam się Janet"]) return random.choice(["Cześć, mam na imię Janet", "Hej, jestem Janet. W czym mogę pomóc?", "Dzień dobry, nazywam się Janet"])
@ -34,7 +32,42 @@ class NLG:
return random.choice(["Dziękujemy za skorzystanie z naszych usług!", "Do widzenia!", "Do zobaczenia!"]) return random.choice(["Dziękujemy za skorzystanie z naszych usług!", "Do widzenia!", "Do zobaczenia!"])
if(domain == "appointment"): if(domain == "appointment"):
if(intent == "book_appointent"): if (intent == "NoOffer"):
return "Proszę sprecyzować zapis na wizytę (lekarz, godzina)"
if (intent == "book_appointent"):
answer = "Zarezerwowano wizytę" answer = "Zarezerwowano wizytę"
print(variable) for key in act[action]:
value = act[action][key]
if(key == "doctor"):
answer += f" do lekarza {value}"
if(key== "datetime"):
answer += f" umówiona na: {value}"
return answer
if (intent == "set_appointment_date"):
value = act[action]["datetime"]
return f"Ustawiono datę wizyty na {value}"
if(domain == "inform"):
if (intent == "Doctors_list"):
value = act[action]["doctors"]
return f"Lista doktorów w naszej placówce: \n{value}"
if (intent == "Location"):
city = act[action]["city"]
street = act[action]["street"]
number = act[action]["number"]
return f"Placówka znajduje się w {city}, {street} {number}"
if (intent == "Opening_Hours"):
value = act[action]["hours"]
return f"Placówka jest otwarta w godzinach {value}"
if (intent == "NoOffer"):
return f"Nie posiadam takiej wiedzy, żeby odpowiedzieć na to pytanie :("
if(domain == "prescription"):
if(intent == "create_prescription" or intent == "collect_prescription"):
answer = f"Odebrano receptę {uuid.uuid4().hex}"
return answer
if(intent == "prescription type"):
return "Wszystkie recepty w naszej placówce są elektroniczne"
if (intent == "NoOffer"):
return f"Nie rozumiem :("

View File

@ -16,10 +16,6 @@
"username": "", "username": "",
"password": "" "password": ""
}, },
"prescription": {
"prescription/type": "",
"prescription/medicine": ""
},
"request_information":{ "request_information":{
"doctor": "", "doctor": "",
"datetime": "", "datetime": "",