1
0
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):
self.results = []
system_action = defaultdict(list)
system_action = defaultdict(dict)
user_action = defaultdict(list)
system_acts = []
while len(state['user_action']) > 0:
@ -47,14 +47,14 @@ class DP():
elif intent == 'appointment/create_appointment':
for x in constraints:
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:
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':
for y in constraints:
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':
for x in constraints_v2:
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:
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':
system_action[("inform", 'Doctors_list')] = {"doctors": "dr. Kolano - okulista, dr. Kowalski - internista, dr. Kaszak - ginekolog"}
elif intent == 'request_information/location':
@ -77,19 +77,19 @@ class DP():
elif intent == 'request_information/cost':
system_action[("inform", 'Cost')] = {"cost": "100 zł"}
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:
system_action[("inform", 'NoOffer')] = []
system_action[("inform", 'NoOffer')] = {'0': '0'}
#################################################################################################
# Reguła 3
if domain == 'end_conversation':
system_action[(domain, 'End_Conversation')] = ['0', '0']
system_action[(domain, 'End_Conversation')] = {'0': '0'}
#################################################################################################
# Reguła 4
if domain == 'greeting':
system_action[(domain, 'Greeting')] = ['0', '0']
system_action[(domain, 'Greeting')] = {'0': '0'}
#################################################################################################
# Reguła 5
@ -98,18 +98,18 @@ class DP():
if intent == 'prescription/request':
for x in constraints_v2:
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:
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':
for x in constraints_v2:
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':
for x in constraints_v2:
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:
system_action[(domain, 'NoOffer')] = []

View File

@ -27,6 +27,18 @@ class Rules_DST(): #Dialogue State Tracker
domain_dic = self.state['belief_state'][domain]
if slot in domain_dic:
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 (slot == 'request_information'):
@ -42,6 +54,6 @@ class Rules_DST(): #Dialogue State Tracker
elif intent == 'end_conversation':
self.state = json.load(open('default_state.json'))
print(self.state)
print("\n")
# print(self.state)
# print("\n")
return self.state

View File

@ -1,4 +1,5 @@
import random
import uuid
class NLG:
"""
@ -22,19 +23,51 @@ class NLG:
if(len(act) == 0):
return "Nie mam już nic do powiedzenia :("
domain, intent = act[0]
for action in act:
domain, intent = action
if(domain == "greeting"):
return random.choice(["Cześć, mam na imię Janet", "Hej, jestem Janet. W czym mogę pomóc?", "Dzień dobry, nazywam się Janet"])
if (domain == "inform"):
return "test"
if(domain == "end_conversation"):
return random.choice(["Dziękujemy za skorzystanie z naszych usług!", "Do widzenia!", "Do zobaczenia!"])
if(domain == "greeting"):
return random.choice(["Cześć, mam na imię Janet", "Hej, jestem Janet. W czym mogę pomóc?", "Dzień dobry, nazywam się Janet"])
if(domain == "appointment"):
if (intent == "NoOffer"):
return "Proszę sprecyzować zapis na wizytę (lekarz, godzina)"
if (intent == "book_appointent"):
answer = "Zarezerwowano wizytę"
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 == "end_conversation"):
return random.choice(["Dziękujemy za skorzystanie z naszych usług!", "Do widzenia!", "Do zobaczenia!"])
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 :("
if(domain == "appointment"):
if(intent == "book_appointent"):
answer = "Zarezerwowano wizytę"
print(variable)

View File

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