Zaktualizuj 'dialogue_system.py'
fix
This commit is contained in:
parent
83bd745164
commit
44b9976aa6
@ -1,7 +1,7 @@
|
|||||||
from modules.NLU import NLU
|
from modules.NLU import NLU
|
||||||
from modules.DST import DST
|
from modules.DST import DST
|
||||||
#from modules.DP import DP
|
from modules.DP import DP
|
||||||
#from modules.NLG import NLG
|
from modules.NLG import NLG
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def format_prediction(prediction, intent):
|
def format_prediction(prediction, intent):
|
||||||
@ -23,8 +23,8 @@ def format_prediction(prediction, intent):
|
|||||||
def main():
|
def main():
|
||||||
nlu = NLU()
|
nlu = NLU()
|
||||||
dst = DST()
|
dst = DST()
|
||||||
#dp = DP()
|
dp = DP()
|
||||||
#nlg = NLG()
|
nlg = NLG()
|
||||||
|
|
||||||
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')
|
||||||
@ -40,39 +40,117 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
user_input = input('> ')
|
user_input = input('> ')
|
||||||
user_input_lr = user_input.lower()
|
user_input_lr = user_input.lower()
|
||||||
if user_input_lr == '/pomoc':
|
flag = False
|
||||||
print('TEKST_POMOCY_WIP')
|
|
||||||
elif user_input_lr == '/koniec':
|
|
||||||
print('Dziękuję za skorzystanie z moich usług. Miłego dnia!')
|
|
||||||
break
|
|
||||||
elif 'rezerw' in user_input_lr:
|
|
||||||
if 'anulo' in user_input_lr:
|
|
||||||
dst.update([['inform', 'Cinema', 'task', 'cancel_book']])
|
|
||||||
print(dst.state)
|
|
||||||
else:
|
|
||||||
dst.update([['inform', 'Cinema', 'task', 'book']])
|
|
||||||
print(dst.state)
|
|
||||||
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:
|
|
||||||
dst.update([['inform', 'Cinema', 'task', 'cancel_buy']])
|
|
||||||
print(dst.state)
|
|
||||||
else:
|
|
||||||
dst.update([['inform', 'Cinema', 'task', 'buy']])
|
|
||||||
print(dst.state)
|
|
||||||
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)
|
|
||||||
elif (('czy' or 'jakie' or 'które') and ('dostęp' or 'woln' or 'zajęt') and 'miejsc') in user_input_lr:
|
|
||||||
dst.update([['inform', 'Cinema', 'task', 'show_seats']])
|
|
||||||
print(dst.state)
|
|
||||||
else:
|
|
||||||
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)
|
||||||
|
for slot in formatted_prediction:
|
||||||
|
if slot[2]=='seat':
|
||||||
|
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')
|
||||||
|
|
||||||
|
elif user_input_lr == '/koniec':
|
||||||
|
print('Dziękuję za skorzystanie z moich usług. Miłego dnia!')
|
||||||
|
break
|
||||||
|
|
||||||
|
elif 'rezerw' in user_input_lr:
|
||||||
|
if 'anulo' in user_input_lr:
|
||||||
|
for slot in slots:
|
||||||
|
if slot == 'B-e-mail' or '@' in slot[0]:
|
||||||
|
print(nlg.update([['cinema','inform','cancel_book',slot[0]]]))
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'cancel_book'],['inform', 'Cinema', 'cancel_book_status',True]])
|
||||||
|
flag = True
|
||||||
|
if not flag:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'cancel_book'],['inform', 'Cinema', 'cancel_book_status',False]])
|
||||||
|
print(nlg.update([['cinema','inform','cancel_book','']]))
|
||||||
|
|
||||||
|
else:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'book']])
|
||||||
|
dst.update(formatted_prediction)
|
||||||
|
for slot,value in dst.state['belief_state']['cinema']['book'].items():
|
||||||
|
if value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
elif slot=="row" and value != '':
|
||||||
|
for slot,value in dst.state['belief_state']['cinema']['semi'].items():
|
||||||
|
if value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
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:
|
||||||
|
for slot in slots:
|
||||||
|
if slot == 'B-e-mail' or '@' in slot[0]:
|
||||||
|
print(nlg.update([['cinema','inform','cancel_buy',slot[0]]]))
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'cancel_buy'],['inform', 'Cinema', 'cancel_buy_status',True]])
|
||||||
|
flag = True
|
||||||
|
if not flag:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'cancel_buy'],['inform', 'Cinema', 'cancel_buy_status',False]])
|
||||||
|
print(nlg.update([['cinema','inform','cancel_buy','']]))
|
||||||
|
|
||||||
|
else:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'buy']])
|
||||||
|
dst.update(formatted_prediction)
|
||||||
|
print(dst.state)
|
||||||
|
for slot,value in dst.state['belief_state']['cinema']['book'].items():
|
||||||
|
if value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
elif slot=="row" and value != '':
|
||||||
|
for slot,value in dst.state['belief_state']['cinema']['semi'].items():
|
||||||
|
if value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
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:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'show_movies']])
|
||||||
|
print(nlg.update([['cinema','offer','task','closestscreening']]))
|
||||||
|
|
||||||
|
elif (('czy' or 'jakie' or 'które') and ('dostęp' or 'woln' or 'zajęt') and 'miejsc') in user_input_lr:
|
||||||
|
dst.update([['inform', 'Cinema', 'task', 'show_seats']])
|
||||||
|
print(nlg.update([['cinema','inform','task','seat']]))
|
||||||
|
|
||||||
|
else:
|
||||||
print(formatted_prediction) # NLU output
|
print(formatted_prediction) # NLU output
|
||||||
dst.update(formatted_prediction)
|
dst.update(formatted_prediction)
|
||||||
print(dst.state) # DST output
|
print(dst.state) # DST output
|
||||||
#DP, NLG...
|
#DP
|
||||||
|
for slot,value in dst.state['belief_state']['cinema']['book'].items():
|
||||||
|
if value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
elif slot=="row" and value != '':
|
||||||
|
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()
|
||||||
|
if input_user.lower() == 'tak':
|
||||||
|
print(nlg.update([['cinema','request',slot,'online']]))
|
||||||
|
dst.update([['inform', 'Cinema', 'payments', 'online']])
|
||||||
|
else:
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
dst.update([['inform', 'Cinema', 'payments', 'in_cinema']])
|
||||||
|
elif value == '':
|
||||||
|
print(nlg.update([['cinema','request',slot,'']]))
|
||||||
|
break
|
||||||
|
elif slot in ["cancel_book_status","cancel_buy_status"] and value =='':
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user