dialogue flow fix

This commit is contained in:
s444417 2022-06-03 09:40:03 +02:00
parent 98f57edf48
commit 9d936403b4
6 changed files with 180 additions and 101 deletions

View File

@ -1,31 +1,103 @@
from urllib import request
class DP:
def __init__(self):
pass
self.questionManager = UserQuestionModule()
def getAction(self, lastUserAct, emptySlots, systemSlots):
def getAction(self, lastUserAct, emptySlots, systemSlots, filledSlots):
systemAct = None
slotVal = None
if ((lastUserAct == "hello") | (lastUserAct == "inform") | (lastUserAct == None)):
# there are no empty slots
if not emptySlots:
# generate reservation id
systemAct = "inform"
slotVal = systemSlots
# there are empty slots
else:
for slot in systemSlots:
if slot in emptySlots:
systemAct = "request"
slotVal = slot
break
for slot in emptySlots:
systemAct = "request"
slotVal = slot
break
return ["Cinema", systemAct, slotVal, ""]
elif (lastUserAct == "request"):
elif (lastUserAct == "request" | lastUserAct == "reqmore"):
# TODO policy for user request
return ["Cinema", "", "", ""]
return ["Cinema", "select", "", ""]
else:
systemAct = "repeat"
return ["Cinema", systemAct, "", ""]
class UserQuestionModule():
def __init__(self):
self.questionSlots = ["title", "date", "time"]
def getQuestionTypes(self):
return self.questionTypes
def getQuestionType(self, filledSlots):
filledSlots = []
# for slot in self.questionSlots
# if "title" in emptySlots:
# questionType = self.questionTypes[0]
# elif "date" in emptySlots:
# questionType = self.questionTypes[1]
# elif "time" in emptySlots:
# questionType = self.getQuestionTypes[2]
# return questionType,
class DBMock():
def __init__(self):
self.shows = {
1: {
"title": "batman",
"date": "21.06",
"time": 19,
"seats": ["a1", "a2", "a3", "a4", "a5",
"b1", "b2", "b3", "b4", "b5",
"c1", "c2", "c3", "c4", "c5",
"d1", "d2", "d3", "d4", "d5",
"e1", "e2", "e3", "e4", "e5",],
"free": ["a1", "a2",
"b2", "b3", "b4",
"d1", "d2",
"e1", "e2", "e3", "e4",],
},
2: {
"title": "batman",
"date": "22.06",
"time": 20,
"seats": ["a1", "a2", "a3", "a4", "a5",
"b1", "b2", "b3", "b4", "b5",
"c1", "c2", "c3", "c4", "c5",
"d1", "d2", "d3", "d4", "d5",
"e1", "e2", "e3", "e4", "e5",],
"free": ["a1", "a2", "a3",
"b2", "b3", "b4",
"d1", "d2",
"e1", "e2", "e3", "e4",],
},
3: {
"title": "zorro",
"date": "23.06",
"time": 21,
"seats": ["a1", "a2", "a3", "a4", "a5",
"b1", "b2", "b3", "b4", "b5",
"c1", "c2", "c3", "c4", "c5",
"d1", "d2", "d3", "d4", "d5",
"e1", "e2", "e3", "e4", "e5",],
"free": ["a1", "a2",
"b1", "b2", "b3", "b4", "b5",
"c4", "c5",
"d1", "d2", "d3", "d4", "d5",
"e1", "e2", "e3", "e4", "e5",],
}
}
def getShows(self, title = None, time = None, timeInterval = None, date = None):
pass

View File

@ -2,36 +2,27 @@ class DST:
def __init__(self):
self.init_session()
# self.value_dict = json.load(open('utils/value_dict.json'))
def update(self, user_act=None):
intentVal = None
# sample user_act from NLU
# user_act = [["inform", "Cinema", "title", "batman"], ["inform", "Cinema", "date", "jutro"]]
for intent, domain, slot, value in user_act:
domain = domain.lower()
intent = intent.lower()
value = value.lower()
slot = slot.lower()
if intentVal is None : intentVal = intent
# all intents are same
if intentVal is None: intentVal = intent
k = slot
# fills slots
if slot in self.state['belief_state']["cinema"]["book"].keys():
self.state['belief_state']["cinema"]["book"][slot] = value
if intent == 'inform':
# saves user intent
self.state['user_action'].append(intentVal)
domain_dic = self.state['belief_state'][domain]
if k in domain_dic['semi']:
self.state['belief_state'][domain]['semi'][k] = value
elif k in domain_dic['book']:
self.state['belief_state'][domain]['book'][k] = value
elif k.lower() in domain_dic['book']:
self.state['belief_state'][domain]['book'][k.lower()] = value
elif intent == 'reqmore':
if domain not in self.state['request_state']:
self.state['request_state'][domain] = {}
if k not in self.state['request_state'][domain]:
self.state['request_state'][domain][k] = 0
self.state['user_action'].append(intentVal)
return self.state
def addSystemAct(self, act):
@ -50,6 +41,13 @@ class DST:
result.append(key)
return result
def getFilledSlots(self):
result = []
for key in self.state['belief_state']["cinema"]["book"].keys():
if self.state['belief_state']["cinema"]["book"][key] != "":
result.append(key)
return result
def getSystemSlots(self):
result = []
for key in self.state['belief_state']["cinema"]["book"].keys():
@ -74,14 +72,9 @@ class DST:
"date": "",
"time": "",
"quantity": "",
"area": "",
"seats": "",
"interval": "",
},
"semi": {
"goal": ""
}
},
}
return state

View File

@ -59,18 +59,32 @@ class NLU:
result.append([intent, 'Cinema', slot, slotValue])
slot = None
slotValue = None
elif tag.split("-")[0] == "B":
slot = tag.split("-")[1]
slotValue = value
elif tag.split("-")[0] == "I":
try:
slotValue += " " + value
except:
slot = tag.split("-")[1]
else:
findedSlot = tag.split("-")[1]
if slot is not None:
if findedSlot == slot:
slotValue += " " + value
else:
result.append([intent, 'Cinema', slot, slotValue])
slot = findedSlot
slotValue = value
else:
slot = findedSlot
slotValue = value
# elif tag.split("-")[0] == "B":
# if slot is not None & findedSlot != slot :
# slot = tag.split("-")[1]
# slotValue = value
# elif tag.split("-")[0] == "I":
# try:
# slotValue += " " + value
# except:
# slot = tag.split("-")[1]
# slotValue = value
if slotValue is not None:
result.append([intent, 'Cinema', slot, slotValue])
if len(result) == 0: result.append([intent, 'Cinema', "", ""])
return result

View File

@ -10,9 +10,9 @@
| area | preferred place to sit | [front, middle] OR [random, aisle]
| interval | time interval | w tym tygodniu OR w następnym tygodniu
| goal | users goal in system | chciałbym zarezerwować(opcjonalne) OR jakie filmy gracie
| reservation_id | reservation number | 32453758
| tickets_type - | tickets types and quantities | [normal, 1] OR [[student, 2], [normal, 1]]
| location - | location of cinema | Poznań Plaza OR Multikino 51
| reservation_id - | reservation number | 32453758

View File

@ -24,7 +24,7 @@ W środku, pomiedzy górnym i środkowym rzędem inform
<3 thankyou
Dzień dobry hello
Chciał bym zamówić bilet na film Minionki dzisiaj o 18.30 inform
czy jest jakis film o godzinie 18:30? request
czy jest jakis film o godzinie 18:30? reqmore
niech będzie ack
1 inform
jakie sš dostępne ulgi?

1 Dzień dobry. hello
24 <3 thankyou
25 Dzień dobry hello
26 Chciał bym zamówić bilet na film Minionki dzisiaj o 18.30 inform
27 czy jest jakis film o godzinie 18:30? request reqmore
28 niech będzie ack
29 1 inform
30 jakie sš dostępne ulgi?

View File

@ -11,8 +11,8 @@
3 na reqmore NoLabel
4 premierę reqmore NoLabel
5 filmu reqmore NoLabel
6 jakie reqmore B-goal
7 premiery reqmore I-goal
6 jakie reqmore B-question
7 premiery reqmore I-question
8 są reqmore NoLabel
9 w reqmore B-interval
10 tym reqmore I-interval
@ -37,27 +37,27 @@
2 17:30 inform B-time
# text: są zniżki studenckie
# intent: reqmore
# intent: null
# slots:
1 są reqmore NoLabel
2 zniżki reqmore NoLabel
3 studenckie reqmore NoLabel
1 są null NoLabel
2 zniżki null NoLabel
3 studenckie null NoLabel
# text: super w takim razie poproszę studnecki
# intent: inform
# intent: null
# slots:
1 super inform NoLabel
2 w inform NoLabel
3 takim inform NoLabel
4 razie inform NoLabel
5 poproszę inform NoLabel
6 studnecki inform NoLabel
1 super null NoLabel
2 w null NoLabel
3 takim null NoLabel
4 razie null NoLabel
5 poproszę null NoLabel
6 studnecki null NoLabel
# text: 1x studencki
# text: 1x bilet
# intent: inform
# slots: 1x:quantity
1 1x inform B-quantity
2 studencki inform NoLabel
2 bilet inform NoLabel
# text: na środku
# intent: inform
@ -80,9 +80,9 @@
1 tak inform NoLabel
# text: normalny
# intent: reqmore
# intent: null
# slots:
1 normalny reqmore NoLabel
1 normalny null NoLabel
# text: super poproszę by miejsca były obok siebie
# intent: inform
@ -96,24 +96,24 @@
7 siebie inform NoLabel
# text: super czy można płacić z góry
# intent: reqmore
# intent: help
# slots:
1 super reqmore NoLabel
2 czy reqmore NoLabel
3 można reqmore NoLabel
4 płacić reqmore NoLabel
5 z reqmore NoLabel
6 góry reqmore NoLabel
1 super help NoLabel
2 czy help NoLabel
3 można help NoLabel
4 płacić help NoLabel
5 z help NoLabel
6 góry help NoLabel
# text: ok czy bilety mam już zarezerwowane
# intent: reqmore
# intent: help
# slots:
1 ok reqmore NoLabel
2 czy reqmore NoLabel
3 bilety reqmore NoLabel
4 mam reqmore NoLabel
5 już reqmore NoLabel
6 zarezerwowane reqmore NoLabel
1 ok help NoLabel
2 czy help NoLabel
3 bilety help NoLabel
4 mam help NoLabel
5 już help NoLabel
6 zarezerwowane help NoLabel
# text: super dziękuję
# intent: bye
@ -140,7 +140,7 @@
1 dzisiaj inform B-date
# text: 16:30
# intent: infomrm
# intent: inform
# slots:
1 16:30 inform B-time
@ -153,7 +153,7 @@
# intent: inform
# slots:
1 chciałbym inform NoLabel
2 anulować inform NoLabel
2 anulować inform B-goal
3 rezerwację inform NoLabel
4 biletu inform NoLabel
@ -161,25 +161,25 @@
# intent: inform
# slots:
1 numer inform NoLabel
2 42069 inform NoLabel
2 42069 inform reservation_id
# text: numer 42068
# intent: inform
# slots:
1 numer inform NoLabel
2 42068 inform NoLabel
2 42068 inform reservation_id
# text: numer 42067
# intent: inform
# slots:
1 numer inform NoLabel
2 42067 inform NoLabel
2 42067 inform reservation_id
# text: chciałbym anulować rezerwację biletu dla imienia i nazwiska jan kowalski
# intent: inform
# slots:
1 chciałbym inform NoLabel
2 anulować inform NoLabel
2 anulować inform B-goal
3 rezerwację inform NoLabel
4 biletu inform NoLabel
5 dla inform NoLabel
@ -190,14 +190,14 @@
10 kowalski inform NoLabel
# text: nie pamiętam czy mogę podać e-mail
# intent: reqmore
# intent: null
# slots:
1 nie reqmore NoLabel
2 pamiętam reqmore NoLabel
3 czy reqmore NoLabel
4 mogę reqmore NoLabel
5 podać reqmore NoLabel
6 e-mail reqmore NoLabel
1 nie null NoLabel
2 pamiętam null NoLabel
3 czy null NoLabel
4 mogę null NoLabel
5 podać null NoLabel
6 e-mail null NoLabel
# text: elo
# intent: hello
@ -221,14 +221,14 @@
12 prawdę inform NoLabel
# text: poproszę listę filmów granych jutro wieczorem
# intent: reqmore inform
# intent: reqmore
# slots: listęfilmów:goaljutro:date,wieczorem:interval
1 poproszę reqmore inform NoLabel
2 listę reqmore inform B-goal
3 filmów reqmore inform I-goal
4 granych reqmore inform NoLabel
5 jutro reqmore inform B-date
6 wieczorem reqmore inform B-interval
1 poproszę reqmore NoLabel
2 listę reqmore B-question
3 filmów reqmore I-question
4 granych reqmore NoLabel
5 jutro reqmore B-date
6 wieczorem reqmore B-interval
# text: chciałbym kupić bilety na transformers
# intent: inform