Beispiel #1
0
 def _get_slot_value(self, slot):
     '''Get value describing user intention for the given slot.
     
     Raises:
         RuntimeError: Cant find value for the given slot.
     '''
     item = DialogueActItem()
     if slot in self.goal.keys():
         return self.goal[slot]
     if slot not in self.goal.keys():#required slot not in goal
         eq_slots = self._get_equivalent_slots(slot)
         for s in eq_slots:#gen value from a equivalent slot
             if s in self.goal.keys():
                 slot = s
                 break
         if slot not in self.goal.keys():#dont have compatible slots, get from default values
             value = self._get_default_slot_value(slot)
             if value is not None:
                 item.value = value
             else:
                 for s in eq_slots:#get default of equivalent slots
                     value = self._get_default_slot_value(s)
                     if value is not None:
                         item.value = value
                         item.name = s
                 if item.value is None:
                     #raise RuntimeError('Cant find value for slot %s and its equivalents slot from goal and default slots'%slot)
                     print '!!!!!!???set to None, Cant find value for slot [%s] and its equivalents slot from goal and default slots'%slot
                     item.value = None
         else:
             item.value=self.goal[slot]
             item.name = slot
     return item.value 
Beispiel #2
0
    def _build_dialogue_act_items(self, act_in, act_out, answer_type, overridden_properties):
        '''Build return acts for a type of answer act.

        Args:
            act_in: The metadata presenting the system act such as slots-values
            act_out: A string figure out the type of answer act such as inform or affirm
            answer_type: A string describe answer type which can be whether direct answer, over answer or complete answer.
            overridden_properties: A dict of properties which will used to override the default setting of return act.

        Returns:
            A list of DialogueActItem object.

        Raises:
            RuntiemError: Cant find value for a slot which requires, in setting, a value must be filled.
            NotImplementedError: The source providing value for a slot was not implemented.
        '''
        #print act_in
        #print '---building', act_out
        #print answer_type
        if act_out not in self.act_used_slots.keys():#saving this action used this slot
            self.act_used_slots[act_out] = set()

        act_out_des = self.metadata['dialogue_act_definitions'][act_out]
        act_out_des = self._override_act_descriptions(overridden_properties, act_out_des)
        #print 'act_out_des_override'
        #iprint(act_out_des)
        da_items = []
        combined_slots = self._get_combined_slots(act_in, act_out_des, answer_type, self.act_used_slots[act_out])
        for slot in combined_slots:
            item = DialogueActItem()
            item.dat = act_out
            if act_out_des['slot_included']:
                item.name = slot
            if act_out_des['value_included']:
                if act_out_des['value_from']=='goal':
                    if slot not in self.goal.keys():#required slot not in goal
                        eq_slots = self._get_equivalent_slots(slot)
                        for s in eq_slots:#gen value from a equivalent slot
                            if s in self.goal.keys():
                                slot = s
                                break
                    if slot not in self.goal.keys():#dont have compatible slots, get from default values
                        value = self._get_default_slot_value(slot)
                        if value is not None:
                            item.value = value
                        else:
                            for s in eq_slots:#get default of equivalent slots
                                value = self._get_default_slot_value(s)
                                if value is not None:
                                    item.value = value
                                    item.name = s
                                    break
                            if item.value is None:
                                raise RuntimeError('Cant find value for slot %s and its equivalents slot from goal and default slots'%slot)
                    else:
                        item.value=self.goal[slot]
                        item.name = slot
                elif act_out_des['value_from']=='sys_da':
                    item.value = act_in['slot_value'][slot]
                elif act_out_des['value_from']=='function':
                    item.value = act_out_des['value_fun']()
                else:
                    raise NotImplementedError('value_from=%s unhandled yet'%act_out_des['value_from'])

            self.act_used_slots[act_out].add(slot)#save to the list of used slot for this act_out
                
            if item not in da_items:
                da_items.append(item)

        act_without_slot = False
        if 'act_without_slot' in act_out_des.keys() and act_out_des['act_without_slot']:
            act_without_slot = True
            da_items.append(DialogueActItem(act_out))
        
        if len(combined_slots)==0 and len(da_items)==0 and not act_without_slot:
            #pass
            print 'Not building act=%s since it requires slots and values but we cant find any slot, value for it'%act_out
            #raise RuntimeError('Cant find any slot, value for the given dialogue act, %s'%act_out)
        return da_items