80 lines
3.1 KiB
Python
80 lines
3.1 KiB
Python
from modules.NLU import NLU
|
|
from modules.DST import DST
|
|
#from modules.DP import DP
|
|
#from modules.NLG import NLG
|
|
import re
|
|
|
|
def format_prediction(prediction, intent):
|
|
out_list = []
|
|
for idx, tup in enumerate(prediction):
|
|
if tup[1][0] == 'B':
|
|
slot_list = [intent, 'Cinema', tup[1][2:], tup[0]]
|
|
for tup in prediction[idx + 1:]:
|
|
if tup[1][0] != 'I':
|
|
break
|
|
else:
|
|
slot_list[3] += ' ' + tup[0]
|
|
out_list.append(slot_list)
|
|
for slot in out_list:
|
|
slot[3] = re.sub("^[!\"#$%&\'()*+,.;:<=>?\[\]^_`{|}~]+", '', slot[3])
|
|
slot[3] = re.sub("[!\"#$%&\'()*+,.;:<=>?\[\]^_`{|}~]+$", '', slot[3])
|
|
return out_list
|
|
|
|
def main():
|
|
nlu = NLU()
|
|
dst = DST()
|
|
#dp = DP()
|
|
#nlg = NLG()
|
|
|
|
nlu.train_slot_model('data/train+test-pl.conllu', 'data/train+test-pl.conllu')
|
|
nlu.train_intent_model('data/NLU_data_intent')
|
|
# nlu.load_slot_model('slot-model-pl')
|
|
# nlu.load_intent_model('intent-model-pl')
|
|
|
|
print('===========================================')
|
|
print('### By otrzymać pomoc, wpisz /pomoc ###')
|
|
print('### By zakończyć rozmowę, wpisz /koniec ###')
|
|
print('Witaj, jestem Usher - system do rezerwacji biletów kinowych. W czym mogę Ci pomóc?')
|
|
|
|
# WIP
|
|
while True:
|
|
user_input = input('> ')
|
|
user_input_lr = user_input.lower()
|
|
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:
|
|
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)
|
|
intent = nlu.predict_intent(user_input)
|
|
formatted_prediction = format_prediction(slots, intent)
|
|
print(formatted_prediction) # NLU output
|
|
dst.update(formatted_prediction)
|
|
print(dst.state) # DST output
|
|
#DP, NLG...
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|