Zaktualizuj 'dialogue_system.py'

fix recognition of seat,row,quantity and reaction to answers
This commit is contained in:
Julian Zabłoński 2022-06-14 14:19:03 +02:00
parent c447c27731
commit d4e143c2ec

View File

@ -30,12 +30,12 @@ def main():
nlu = NLU() nlu = NLU()
dst = DST() dst = DST()
# dp = DP() # dp = DP()
nlg = NLG() nlg = NLG(dst)
nlu.train_slot_model('data/train+test-pl.conllu', 'data/train+test-pl.conllu') nlu.train_slot_model('data/train+test-pl.conllu', 'data/train+test-pl.conllu')
nlu.train_intent_model('data/NLU_data_intent') nlu.train_intent_model('data/NLU_data_intent')
#nlu.load_slot_model('slot-model-pl') # nlu.load_slot_model('slot-model-pl')
#nlu.load_intent_model('intent-model-pl') # nlu.load_intent_model('intent-model-pl')
start = time.time() start = time.time()
turns = 0 turns = 0
@ -56,15 +56,107 @@ def main():
slots = nlu.predict_slots(user_input) slots = nlu.predict_slots(user_input)
intent = nlu.predict_intent(user_input) intent = nlu.predict_intent(user_input)
formatted_prediction = format_prediction(slots, intent) formatted_prediction = format_prediction(slots, intent)
#print(formatted_prediction)
for slot in formatted_prediction: for slot in formatted_prediction:
if len(formatted_prediction)<2:
if dst.state['system_action'][-1] != slot:
formatted_prediction.remove(slot)
formatted_prediction.append([slot[0],slot[1],dst.state['system_action'][-1][0][2],slot[3]])
if slot[2]=='seat': if slot[2]=='seat':
if ',' in slot[3]: if ',' in slot[3]:
seat,row = slot[3].split(',') seat,row = slot[3].split(',')
formatted_prediction.remove(['inform', 'Cinema', 'seat', slot[3]]) formatted_prediction.remove(['inform', 'Cinema', 'seat', slot[3]])
formatted_prediction.append(['inform', 'Cinema', 'seat', seat]) formatted_prediction.append(['inform', 'Cinema', 'seat', seat])
formatted_prediction.append(['inform', 'Cinema', 'row', f' {row}']) formatted_prediction.append(['inform', 'Cinema', 'row', f' {row}'])
if 'rzęd' in user_input_lr:
formatted_prediction_tmp = formatted_prediction.copy()
user_input_splited = user_input_lr.split()
for slots in formatted_prediction:
if slots[2] =='row' or slots[2]=='seat' or slots[2] =='quantity':
formatted_prediction_tmp.remove(slots)
formatted_prediction = formatted_prediction_tmp.copy()
if 'miejsc' not in user_input_lr and 'bilet' not in user_input_lr:
for i in range(len(user_input_splited)-1):
if 'rzęd' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int)and i==0:
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
elif 'miejsc' in user_input_lr and 'bilet' not in user_input_lr:
for i in range(len(user_input_splited)-1):
print(user_input_splited[i],user_input_splited[i+1])
if 'rzęd' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int)and i==0:
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
if 'miejsc' in user_input_splited[i]:
try:
if i==0 and isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i+1]])
elif 'miejsc' not in user_input_lr and 'bilet' in user_input_lr:
for i in range(len(user_input_splited)-1):
print(user_input_splited[i],user_input_splited[i+1])
if 'rzęd' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int)and i==0:
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
if 'miejsc' in user_input_splited[i]:
try:
if i==0 and isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i+1]])
elif 'miejsc' in user_input_lr and 'bilet' in user_input_lr:
for i in range(len(user_input_splited)-1):
if 'rzęd' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int)and i==0:
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'row', user_input_splited[i+1]])
if 'miejsc' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int) and i==0:
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'seat', user_input_splited[i+1]])
if 'bilet' in user_input_splited[i]:
try:
if isinstance(int(user_input_splited[i+1]),int)and i==0:
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i+1]])
elif isinstance(int(user_input_splited[i-1]),int):
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i-1]])
except:
if isinstance(int(user_input_splited[i+1]),int):
formatted_prediction.append(['inform', 'Cinema', 'quantity', user_input_splited[i+1]])
if user_input_lr == '/pomoc': if user_input_lr == '/pomoc':
print('System Usher pozwala na:\n1. Rezerwację biletu\n2. Anulowanie rezerwacji biletu\n3. Zakup biletu\n4. Anulowanie zakupu biletu\n5. Sprawdzenie repertuaru\n6. Sprawdzenie dostępności miejsc') print('System Usher pozwala na:\n1. Rezerwację biletu\n2. Anulowanie rezerwacji biletu\n3. Zakup biletu\n4. Anulowanie zakupu biletu\n5. Sprawdzenie repertuaru\n6. Sprawdzenie dostępności miejsc')
@ -80,7 +172,6 @@ def main():
dst = DST() dst = DST()
# dp = DP() ? # dp = DP() ?
print('Witaj, jestem Usher - system do rezerwacji biletów kinowych. W czym mogę Ci pomóc?') print('Witaj, jestem Usher - system do rezerwacji biletów kinowych. W czym mogę Ci pomóc?')
elif 'rezerw' in user_input_lr: elif 'rezerw' in user_input_lr:
if 'anulo' in user_input_lr: if 'anulo' in user_input_lr:
flag=False flag=False
@ -145,15 +236,16 @@ def main():
if not flag: if not flag:
print(nlg.update([['cinema','offer','closestscreening','']])) print(nlg.update([['cinema','offer','closestscreening','']]))
elif (('czy' or 'jakie' or 'które') and ('dostęp' or 'woln' or 'zajęt') and 'miejsc') in user_input_lr: elif ('czy' or 'jakie' or 'które') and ('dostęp' or 'woln' or 'zajęt') in user_input_lr:
dst.update([['offer', 'Cinema', 'task', 'show_seats']]) if 'miejsce' in user_input_lr:
flag=False dst.update([['offer', 'Cinema', 'task', 'show_seats']])
for slot in slots: flag=False
if slot[0] in value_dict['train']['seat']: for slot in slots:
print(nlg.update([['cinema','offer','seat',slot[0]]])) if slot[0] in value_dict['train']['seat']:
flag = True print(nlg.update([['cinema','offer','seat',slot[0]]]))
if not flag: flag = True
print(nlg.update([['cinema','offer','seat','']])) if not flag:
print(nlg.update([['cinema','offer','seat','']]))
elif len(formatted_prediction)<1: elif len(formatted_prediction)<1:
print('Nie do końca zrozumiałem mógłbyś/mogłabyś powtórzyć? ') print('Nie do końca zrozumiałem mógłbyś/mogłabyś powtórzyć? ')
@ -190,6 +282,4 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()