Zaktualizuj 'dialogue_system.py'

fix
This commit is contained in:
Julian Zabłoński 2022-06-08 09:25:32 +02:00
parent 22310185d6
commit 5ba45186a1

View File

@ -1,11 +1,11 @@
from modules.NLU import NLU
from modules.DST import DST
from modules.DP import DP
# from modules.DP import DP
from modules.NLG import NLG
import json
import re
value_dict = json.load(open('value_dict.json'))
value_dict = json.load(open(r'C:\Users\User\VisualStudio\Diagramy\aitech-sd-lab\modules\value_dict.json'))
def format_prediction(prediction, intent):
out_list = []
@ -26,7 +26,7 @@ def format_prediction(prediction, intent):
def main():
nlu = NLU()
dst = DST()
dp = DP()
# dp = DP()
nlg = NLG()
nlu.train_slot_model('data/train+test-pl.conllu', 'data/train+test-pl.conllu')
@ -47,17 +47,16 @@ def main():
slots = nlu.predict_slots(user_input)
intent = nlu.predict_intent(user_input)
formatted_prediction = format_prediction(slots, intent)
print(formatted_prediction)
for slot in formatted_prediction:
if slot[2]=='seat':
if ',' in slot[3]: # ???
if ',' in slot[3]:
seat,row = slot[3].split(',')
formatted_prediction.remove(['inform', 'Cinema', 'seat', slot[3]])
formatted_prediction.append(['inform', 'Cinema', 'seat', seat])
formatted_prediction.append(['inform', 'Cinema', 'row', f' {row}'])
if format_prediction == []:
print('Czy mogę w czymś jeszcze pomóc? ')
if user_input_lr == '/pomoc':
print('TEKST_POMOCY_WIP')
@ -67,6 +66,7 @@ def main():
elif 'rezerw' in user_input_lr:
if 'anulo' in user_input_lr:
flag=False
for slot in slots:
if slot == 'B-e-mail' or '@' in slot[0]:
print(nlg.update([['cinema','inform','cancel_book',slot[0]]]))
@ -91,8 +91,9 @@ def main():
elif slot in ["cancel_book_status","cancel_buy_status"] and value =='':
continue
elif 'kup' in user_input_lr or ('zwr' and 'bilet') in user_input_lr:
if 'anulo' in user_input_lr or 'zwr' in user_input_lr:
flag=False
for slot in slots:
if slot == 'B-e-mail' or '@' in slot[0]:
print(nlg.update([['cinema','inform','cancel_buy',slot[0]]]))
@ -118,18 +119,30 @@ def main():
elif slot in ["cancel_book_status","cancel_buy_status"] and value =='':
continue
elif (('jak' or 'któr') and 'film') in user_input_lr or 'repertuar' in user_input_lr:
elif (('jak' or 'któr') and 'film') in user_input_lr or 'repertuar' in user_input_lr:
dst.update([['inform', 'Cinema', 'task', 'show_movies']])
print(dst.state)
flag=False
for slot in slots:
if slot[0] in value_dict['train']['date'] or slot[0] in value_dict['train']['day'] or slot[0] in ['dziś','jutro','pojutrze']:
print(nlg.update([['cinema','inform','closestscreening',slot[0]]]))
print(nlg.update([['cinema','offer','closestscreening',slot[0]]]))
flag = True
if not flag:
print(nlg.update([['cinema','inform','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:
dst.update([['offer', 'Cinema', 'task', 'show_seats']])
print(nlg.update([['cinema','offer','seat','']]))
print(dst.state)
flag=False
for slot in slots:
if slot[0] in value_dict['train']['seat']:
print(nlg.update([['cinema','offer','seat',slot[0]]]))
flag = True
if not flag:
print(nlg.update([['cinema','offer','seat','']]))
elif len(formatted_prediction)<1:
print('Nie do końca zrozumiałem mógłbyś/mogłabyś powtórzyć? ')
else:
print(formatted_prediction) # NLU output
@ -144,7 +157,7 @@ def main():
for slot,value in dst.state['belief_state']['cinema']['semi'].items():
if slot == 'payments' and value == '':
print('Czy chciałbyś dokonać płatności online?')
input_user = input('> ')
input_user = input()
if input_user.lower() == 'tak':
print(nlg.update([['cinema','request',slot,'online']]))
dst.update([['inform', 'Cinema', 'payments', 'online']])
@ -164,3 +177,4 @@ def main():
if __name__ == '__main__':
main()