Even better DP!!!!

This commit is contained in:
Dominik Strzako 2021-05-31 00:01:31 +02:00
parent af7b8a8045
commit 2fd3de96b4
3 changed files with 33 additions and 12 deletions

View File

@ -38,6 +38,7 @@ class DP():
domain, intent = user_act domain, intent = user_act
constraints = [(slot, value) for slot, value in state['belief_state'][domain.lower()].items() if value != ''] constraints = [(slot, value) for slot, value in state['belief_state'][domain.lower()].items() if value != '']
print(domain) print(domain)
print(intent) print(intent)
print(constraints) print(constraints)
@ -59,15 +60,18 @@ class DP():
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')].append([y[0], y[1]])
################################################################################################# #################################################################################################
# Reguła 2 # Reguła 2
if domain == 'request_information': if domain == 'request_information':
constraints_v2 = [(slot, value) for slot, value in state['request_state'][domain.lower()].items() if value != '']
if intent == 'request_information/available_dates': if intent == 'request_information/available_dates':
for x in constraints: 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')].append([x[0], x[1]])
for y in constraints: 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')].append([y[0], y[1]])
elif intent == 'request_information/doctors': elif intent == 'request_information/doctors':
@ -94,22 +98,23 @@ class DP():
################################################################################################# #################################################################################################
# Reguła 5 # Reguła 5
if domain == 'prescription': if domain == 'prescription':
constraints_v2 = [(slot, value) for slot, value in state['request_state'][domain.lower()].items() if value != '']
if intent == 'prescription/request': if intent == 'prescription/request':
for x in constraints: 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')].append([x[0], x[1]])
for y in constraints: 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')].append([y[0], y[1]])
elif intent == 'prescription/collect': elif intent == 'prescription/collect':
for x in constraints: 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')].append([x[0], x[1]])
elif intent == 'prescription/type': elif intent == 'prescription/type':
for x in constraints: 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')].append([x[0], x[1]])
if len(constraints) == 0: if len(constraints_v2) == 0:
system_action[(domain, 'NoOffer')] = [] system_action[(domain, 'NoOffer')] = []
print(system_action) print(system_action)

View File

@ -35,12 +35,22 @@ class Rules_DST(): #Dialogue State Tracker
if(domain in slot): if(domain in slot):
slot.replace(domain + "/", '') slot.replace(domain + "/", '')
domain_dic = self.state['belief_state'][domain] if domain not in self.state['request_state']:
if slot in domain_dic: self.state['request_state'][domain] = {}
self.state['belief_state'][domain][slot] = value if slot not in self.state['request_state'][domain]:
self.state['request_state'][domain][slot] = value
elif intent == 'end_conversation': if 'request_information' in intent:
self.state = json.load(open('default_state.json')) if (slot == 'request_information'):
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
print(self.state) print(self.state)
return self.state return self.state

View File

@ -19,6 +19,12 @@
"prescription": { "prescription": {
"prescription/type": "", "prescription/type": "",
"prescription/medicine": "" "prescription/medicine": ""
},
"request_information":{
"doctor": "",
"datetime": "",
"appointment": "",
"appointment/type": ""
} }
}, },
"request_state": {}, "request_state": {},