Added state facts

This commit is contained in:
Marcin Kostrzewski 2022-06-08 10:15:44 +02:00
parent 4abdf95b9a
commit dcf6931529

View File

@ -4,6 +4,11 @@ dialogue_state = {
# topics will be an array of dicts structured similar to this # topics will be an array of dicts structured similar to this
# {'act': 'notifications', 'slots': [('time_when', None), ('liczba', ''), ('timeunit', None)]} # {'act': 'notifications', 'slots': [('time_when', None), ('liczba', ''), ('timeunit', None)]}
'topics': [], 'topics': [],
# facts is a dict of contextual data such as selected repo and a timeframe
'facts': {
'repo' : '',
'time': ''
},
'counter': 0 'counter': 0
} }
@ -36,6 +41,18 @@ def append_or_merge_frame(frame, dialogue_state):
dialogue_state['topics'].append(frame) dialogue_state['topics'].append(frame)
def update_facts_if_needed(slot):
global dialogue_state
if slot[1] is None or slot[1] == '':
return
if slot[0] == 'repo':
dialogue_state['facts']['repo'] = slot[1]
elif slot[0] == 'time':
dialogue_state['facts']['time'] = slot[1]
def append_or_merge_slots(frame_slots, state_slots): def append_or_merge_slots(frame_slots, state_slots):
""" """
This function expects both parameters to be an array This function expects both parameters to be an array
@ -45,6 +62,7 @@ def append_or_merge_slots(frame_slots, state_slots):
for frame_slot in frame_slots: for frame_slot in frame_slots:
merged = False merged = False
for i in range(len(state_slots)): for i in range(len(state_slots)):
update_facts_if_needed(frame_slot[i])
if state_slots[i][0] == frame_slot[0]: if state_slots[i][0] == frame_slot[0]:
merged = True merged = True
# Do not merge empty incomming slots # Do not merge empty incomming slots
@ -64,3 +82,5 @@ def reset_state_if_needed(frame, dialogue_state):
if frame['act'] == "hello" or frame['act'] == "bye": if frame['act'] == "hello" or frame['act'] == "bye":
dialogue_state['topics'] = [] dialogue_state['topics'] = []
dialogue_state['counter'] = 0 dialogue_state['counter'] = 0
# should we reset 'facts' aswell?