From 9d936403b4467783a9024278ec48ad53f06bd69c Mon Sep 17 00:00:00 2001 From: s444417 Date: Fri, 3 Jun 2022 09:40:03 +0200 Subject: [PATCH] dialogue flow fix --- src/components/DP.py | 98 ++++++++++++++++++++++---- src/components/DST.py | 47 ++++++------- src/components/NLU.py | 30 +++++--- tasks/zad5/Readme.md | 2 +- tasks/zad8/pl/dataSentence/test.tsv | 2 +- tasks/zad8/pl/train.conllu | 102 ++++++++++++++-------------- 6 files changed, 180 insertions(+), 101 deletions(-) diff --git a/src/components/DP.py b/src/components/DP.py index 38242ec..e14ff8a 100644 --- a/src/components/DP.py +++ b/src/components/DP.py @@ -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, "", ""] - \ No newline at end of file + + +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 diff --git a/src/components/DST.py b/src/components/DST.py index 72e4261..cde7e0d 100644 --- a/src/components/DST.py +++ b/src/components/DST.py @@ -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 - - if intent == 'inform': - - 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) + # fills slots + if slot in self.state['belief_state']["cinema"]["book"].keys(): + self.state['belief_state']["cinema"]["book"][slot] = value + + # saves user intent + 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 + \ No newline at end of file diff --git a/src/components/NLU.py b/src/components/NLU.py index a263df1..103b716 100644 --- a/src/components/NLU.py +++ b/src/components/NLU.py @@ -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 diff --git a/tasks/zad5/Readme.md b/tasks/zad5/Readme.md index 75c7481..8b0bc96 100644 --- a/tasks/zad5/Readme.md +++ b/tasks/zad5/Readme.md @@ -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 diff --git a/tasks/zad8/pl/dataSentence/test.tsv b/tasks/zad8/pl/dataSentence/test.tsv index 2ef0b94..a850f5f 100644 --- a/tasks/zad8/pl/dataSentence/test.tsv +++ b/tasks/zad8/pl/dataSentence/test.tsv @@ -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? diff --git a/tasks/zad8/pl/train.conllu b/tasks/zad8/pl/train.conllu index 9d7959a..be92206 100644 --- a/tasks/zad8/pl/train.conllu +++ b/tasks/zad8/pl/train.conllu @@ -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