Beispiel #1
0
    def work_entity_retrieval(self, belief, global_summary):
        '''
        '''
        array_slot_summary = SummaryUtils.arraySlotSummary(belief, self.domainString)
        logger.debug(str(global_summary))
        logger.debug('HDC policy: getGlobal') 
        done, output = self._getGlobal(belief, global_summary)
        
        if not done:
            logger.debug('HDC policy: getConfirmSelect')
            done, output = self._getConfirmSelect(belief, array_slot_summary)
        if not done:
            logger.debug('HDC policy: getInform')
            inform_summary = []
            for num_accepted in range(1, MAX_NUM_ACCEPTED+1):
                temp = SummaryUtils.actionSpecificInformSummary(belief, num_accepted, self.domainString)
                inform_summary.append(temp)
                       
            done, output = self._getInform(belief, global_summary, inform_summary)
        if not done:
            logger.debug('HDC policy: getRequest')
            done, output = self._getRequest(belief, array_slot_summary)
        if not done:
            logger.warning("HDCPolicy couldn't find action: execute reqmore().")
            output = 'reqmore()'

        if output == 'badact()' or output == 'null()':
            logger.warning('HDCPolicy chose bad or null action')
            output = 'null()'

        if self.use_confreq:
            #TODO - known problem here if use_confreq is True (ie being used)  FIXME
            output = PolicyUtils.add_venue_count(output, belief)
        return output
Beispiel #2
0
    def getNonExecutable(self, belief, lastSystemAction):
        '''
        Set of rules defining the mask over the action set, given the current belief state
        :param belief: the current master belief
        :type belief: dict
        :param lastSystemAction: the system action of the previous turn
        :type lastSystemAction: string
        :return: list of non-executable (masked) actions
        '''

        array_slot_summary = SummaryUtils.arraySlotSummary(belief, self.domainString)
        array_slot_summary_rel = SummaryUtilsRel.arraySlotSummaryRel(belief, self.domainString)
        global_summary = SummaryUtils.globalSummary(belief, self.domainString)
        if global_summary['GLOBAL_BYALTERNATIVES'] and not global_summary['GLOBAL_THANKYOU'] and not global_summary['GLOBAL_ACK']:
            self.alternatives_requested = True

        nonexec = ['pass']

        for action in self.action_names:
            mask_action = False
            
            if 'rel' in action:
                if "request_" in action:
                    nonexec.append(action)
#                     pass
#                     if mask_action and self.request_mask:
#                         nonexec.append(action)
    
                elif "select_" in action:
                    slot_summary = array_slot_summary_rel['_'.join(action.split('_')[2:])]
                    top_prob = slot_summary['TOPHYPS'][0][1]
                    sec_prob = slot_summary['TOPHYPS'][1][1]
                    if top_prob == 0 or sec_prob == 0:
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                elif "confirm_" in action:
                    slot_summary = array_slot_summary_rel['_'.join(action.split('_')[2:])]
                    top_prob = slot_summary['TOPHYPS'][0][1]
                    if top_prob == 0:
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                
            else:
                if action == "inform":
                    acceptance_list = SummaryUtils.getTopBeliefs(belief, domainString=self.domainString)
                    discriminable = SummaryUtils.acceptanceListCanBeDiscriminated(acceptance_list,
                                                                                                         self.domainString)
                    if not global_summary['GLOBAL_BYCONSTRAINTS']:
                        mask_action = True
                    if global_summary['GLOBAL_COUNTACCEPTED'] < self.inform_count_accepted and discriminable:
                        mask_action = True
                    if mask_action and self.inform_mask:
                        nonexec.append(action)
    
                elif action == "inform_byname":
                    if not global_summary['GLOBAL_BYNAME']:
                        mask_action = True
                    if belief['features']['lastInformedVenue'] == '' \
                            and SummaryUtils.getTopBelief(belief['beliefs']['name'])[0] == '**NONE**' :
                        mask_action = True
                    if mask_action and self.inform_mask:
                        nonexec.append(action)
    
                elif action == "inform_alternatives":
                    if not self.alternatives_requested:
                        mask_action = True
                    if belief['features']['lastInformedVenue'] == '':
                        mask_action = True
                    if mask_action and self.inform_mask:
                        nonexec.append(action)
    
                elif action == "bye":
                    if not global_summary['GLOBAL_FINISHED']:
                        mask_action = True
                    if mask_action and self.bye_mask:
                        nonexec.append(action)
    
                elif action == "repeat":
                    if not global_summary['GLOBAL_REPEAT'] or lastSystemAction is None:
                        mask_action = True
                    mask_action = True  # ic340: this action is "deactivated" because simuser doesnt know how to react to it
                    if mask_action:
                        nonexec.append(action)
    
                elif action == "reqmore":
                    if belief['features']['lastInformedVenue'] == '':
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                elif action == "restart":
                    if not global_summary['GLOBAL_RESTART']:
                        mask_action = True
                    mask_action = True  # ic340: this action is "deactivated" because simuser doesnt know how to react to it
                    if mask_action:
                        nonexec.append(action)
    
                elif "request_" in action:
                    pass
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                elif "select_" in action:
                    slot_summary = array_slot_summary[action.split("_")[1]]
                    top_prob = slot_summary['TOPHYPS'][0][1]
                    sec_prob = slot_summary['TOPHYPS'][1][1]
                    if top_prob == 0 or sec_prob == 0:
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                elif "confirm_" in action:
                    slot_summary = array_slot_summary[action.split("_")[1]]
                    top_prob = slot_summary['TOPHYPS'][0][1]
                    if top_prob == 0:
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)
    
                elif "confreq_" in action:
                    slot_summary = array_slot_summary[action.split("_")[1]]
                    top_prob = slot_summary['TOPHYPS'][0][1]
                    if top_prob == 0:
                        mask_action = True
                    if mask_action and self.request_mask:
                        nonexec.append(action)

        logger.dial('masked inform actions:' + str([act for act in nonexec if 'inform' in act]))
        return nonexec