Zaktualizuj 'dialogue_system.py'
fix
This commit is contained in:
parent
22310185d6
commit
5ba45186a1
@ -1,11 +1,11 @@
|
|||||||
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 json
|
import json
|
||||||
import re
|
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):
|
def format_prediction(prediction, intent):
|
||||||
out_list = []
|
out_list = []
|
||||||
@ -26,7 +26,7 @@ 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')
|
||||||
@ -47,16 +47,15 @@ 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 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 format_prediction == []:
|
|
||||||
print('Czy mogę w czymś jeszcze pomóc? ')
|
|
||||||
|
|
||||||
if user_input_lr == '/pomoc':
|
if user_input_lr == '/pomoc':
|
||||||
print('TEKST_POMOCY_WIP')
|
print('TEKST_POMOCY_WIP')
|
||||||
@ -67,6 +66,7 @@ def main():
|
|||||||
|
|
||||||
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
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
if slot == 'B-e-mail' or '@' in slot[0]:
|
if slot == 'B-e-mail' or '@' in slot[0]:
|
||||||
print(nlg.update([['cinema','inform','cancel_book',slot[0]]]))
|
print(nlg.update([['cinema','inform','cancel_book',slot[0]]]))
|
||||||
@ -93,6 +93,7 @@ def main():
|
|||||||
elif 'kup' in user_input_lr or ('zwr' and 'bilet') in user_input_lr:
|
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:
|
if 'anulo' in user_input_lr or 'zwr' in user_input_lr:
|
||||||
|
flag=False
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
if slot == 'B-e-mail' or '@' in slot[0]:
|
if slot == 'B-e-mail' or '@' in slot[0]:
|
||||||
print(nlg.update([['cinema','inform','cancel_buy',slot[0]]]))
|
print(nlg.update([['cinema','inform','cancel_buy',slot[0]]]))
|
||||||
@ -120,17 +121,29 @@ def main():
|
|||||||
|
|
||||||
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']])
|
dst.update([['inform', 'Cinema', 'task', 'show_movies']])
|
||||||
|
print(dst.state)
|
||||||
|
flag=False
|
||||||
for slot in slots:
|
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']:
|
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
|
flag = True
|
||||||
if not flag:
|
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:
|
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']])
|
dst.update([['offer', 'Cinema', 'task', 'show_seats']])
|
||||||
|
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','']]))
|
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:
|
else:
|
||||||
print(formatted_prediction) # NLU output
|
print(formatted_prediction) # NLU output
|
||||||
dst.update(formatted_prediction)
|
dst.update(formatted_prediction)
|
||||||
@ -144,7 +157,7 @@ def main():
|
|||||||
for slot,value in dst.state['belief_state']['cinema']['semi'].items():
|
for slot,value in dst.state['belief_state']['cinema']['semi'].items():
|
||||||
if slot == 'payments' and value == '':
|
if slot == 'payments' and value == '':
|
||||||
print('Czy chciałbyś dokonać płatności online?')
|
print('Czy chciałbyś dokonać płatności online?')
|
||||||
input_user = input('> ')
|
input_user = input()
|
||||||
if input_user.lower() == 'tak':
|
if input_user.lower() == 'tak':
|
||||||
print(nlg.update([['cinema','request',slot,'online']]))
|
print(nlg.update([['cinema','request',slot,'online']]))
|
||||||
dst.update([['inform', 'Cinema', 'payments', 'online']])
|
dst.update([['inform', 'Cinema', 'payments', 'online']])
|
||||||
@ -164,3 +177,4 @@ def main():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user