This commit is contained in:
Anna Nowak 2021-06-06 12:09:20 +02:00
parent eecfcb2b03
commit c9f0dfeb3a
4 changed files with 39 additions and 36 deletions

View File

@ -28,8 +28,8 @@ class Janet:
def process(self, command):
act = self.nlu_v2.test_nlu(command)
return self.dp.predict(self.dst.update(act))
#return self.nlg.change_to_text(dest_act)
system_acts = self.dp.predict(self.dst.update_user(act))
return self.nlg.change_to_text(system_acts)
def main():

View File

@ -1,7 +1,4 @@
from collections import defaultdict
import copy
import json
from copy import deepcopy
class DP():
"""
@ -17,14 +14,14 @@ class DP():
self.results = []
system_action = defaultdict(list)
user_action = defaultdict(list)
for intent, domain, slot, value in state['user_action']:
system_acts = []
while len(state['user_action']) > 0:
intent, domain, slot, value = state['user_action'].pop(0)
user_action[(domain, intent)].append((slot, value))
for user_act in user_action:
self.update_system_action(user_act, user_action, state, system_action)
system_acts.append(self.update_system_action(user_act, user_action, state, system_action))
system_acts = [[intent, domain, slot, value] for (domain, intent), slots in system_action.items() for slot, value in slots]
state['system_action'] = system_acts
return system_acts
@ -74,25 +71,25 @@ class DP():
if(y[0] == 'datetime'):
system_action[(domain, 'date_info')].append([y[0], y[1]])
elif intent == 'request_information/doctors':
system_action[(domain, 'Doctors_list')] = []
system_action[("inform", 'Doctors_list')] = {"doctors": "dr. Kolano - okulista, dr. Kowalski - internista, dr. Kaszak - ginekolog"}
elif intent == 'request_information/location':
system_action[(domain, 'Location')] = []
system_action[("inform", 'Location')] = {"street": "Marszałkowska", "number": "45", "city": "Poznań"}
elif intent == 'request_information/cost':
system_action[(domain, 'Cost')] = []
system_action[("inform", 'Cost')] = {"cost": "100 zł"}
elif intent == 'request_information/opening_hours':
system_action[(domain, 'Opening_Hours')] = []
system_action[("inform", 'Opening_Hours')] = ["hours", ['8:00 - 16:00']]
elif len(constraints) == 0:
system_action[(domain, 'NoOffer')] = []
system_action[("inform", 'NoOffer')] = []
#################################################################################################
# Reguła 3
if domain == 'end_conversation':
system_action[(domain, 'End_Conversation')].append(['0', '0'])
system_action[(domain, 'End_Conversation')] = ['0', '0']
#################################################################################################
# Reguła 4
if domain == 'greeting':
system_action[(domain, 'Greeting')].append(['0', '0'])
system_action[(domain, 'Greeting')] = ['0', '0']
#################################################################################################
# Reguła 5
@ -116,6 +113,6 @@ class DP():
if len(constraints_v2) == 0:
system_action[(domain, 'NoOffer')] = []
#return system_action
return system_action
## Brakuje: Rejestracja, Login, Hasło, affirm, deny

View File

@ -11,7 +11,7 @@ class Rules_DST(): #Dialogue State Tracker
def __init__(self):
self.state = json.load(open('default_state.json'))
def update(self, user_acts=None):
def update_user(self, user_acts=None):
for intent, domain, slot, value in user_acts:
self.state["user_action"].append([intent, domain, slot, value])
if domain in ['password', 'name', 'email', 'enter_email', 'enter_name']:
@ -27,18 +27,6 @@ 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'):
@ -51,7 +39,9 @@ class Rules_DST(): #Dialogue State Tracker
self.state['request_state'][domain] = {}
if slot not in self.state['request_state'][domain]:
self.state['request_state'][domain][slot] = value
elif intent == 'end_conversation':
self.state = json.load(open('default_state.json'))
print(self.state)
print("\n")
return self.state
return self.state

View File

@ -1,3 +1,5 @@
import random
class NLG:
"""
Moduł, który tworzy reprezentację tekstową aktu systemowego wybranego przez taktykę dialogu.
@ -9,10 +11,24 @@ class NLG:
def __init__(self):
pass
def change_to_text(self, act_vector):
def change_to_text(self, system_acts):
"""
Funkcja zamieniająca akt systemu na tekst rozumiany przez użytkownika.
"""
if(act_vector == [0, 0]):
return "Cześć, mam na imię Janet"
return "Nie rozumiem"
if(len(system_acts) == 0):
return "Nie mam już nic do powiedzenia :("
act = system_acts.pop(0)
if(len(act) == 0):
return "Nie mam już nic do powiedzenia :("
for variable in act:
domain, intent = variable
if (domain == "inform"):
return "test"
if(domain == "greeting"):
return random.choice(["Cześć, mam na imię Janet", "Hej, jestem Janet. W czym mogę pomóc?", "Dzień dobry, nazywam się Janet"])
elif(domain == "end_conversation"):
return random.choice(["Dziękujemy za skorzystanie z naszych usług!", "Do widzenia!", "Do zobaczenia!"])