def getInform(self, belief):
        """
        """
        act = "null()"
        done = False
        global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
        inform_summary = []
        for num_accepted in range(1, MAX_NUM_ACCEPTED + 1):
            inform_summary.append(SummaryMapping.actionSpecificInformSummary(belief, num_accepted, self.domainUtil))
        count80 = global_summary["GLOBAL_COUNT80"]
        offer_happened = global_summary["GLOBAL_OFFERHAPPENED"]

        if count80 >= MAX_NUM_ACCEPTED:
            count80 = MAX_NUM_ACCEPTED - 1

        arr = inform_summary[count80]
        first = arr[0]  # True if there is no matching entities
        second = arr[1]  # True if there is one matching entities
        # third = arr[2]  # True if there is two~four matching entities
        discr = arr[4]  # True if we can discriminate more

        requested_slots = DMUtils.getRequestedSlots(belief)
        # if (first or second or not discr or count80 >= len(Settings.ontology['system_requestable'])) and len(requested_slots)==0:
        act = DMUtils.getInformAction(count80, belief, self.domainUtil)
        if act != "null()":
            done = True
        return [done, act]
    def getInform(self, belief):
        '''
        '''
        act = "null()"
        done = False
        global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
        inform_summary = []
        for num_accepted in range(1, MAX_NUM_ACCEPTED + 1):
            inform_summary.append(
                SummaryMapping.actionSpecificInformSummary(
                    belief, num_accepted, self.domainUtil))
        count80 = global_summary['GLOBAL_COUNT80']
        offer_happened = global_summary['GLOBAL_OFFERHAPPENED']

        if count80 >= MAX_NUM_ACCEPTED:
            count80 = MAX_NUM_ACCEPTED - 1

        arr = inform_summary[count80]
        first = arr[0]  # True if there is no matching entities
        second = arr[1]  # True if there is one matching entities
        #third = arr[2]  # True if there is two~four matching entities
        discr = arr[4]  # True if we can discriminate more

        requested_slots = DMUtils.getRequestedSlots(belief)
        #if (first or second or not discr or count80 >= len(Settings.ontology['system_requestable'])) and len(requested_slots)==0:
        act = DMUtils.getInformAction(count80, belief, self.domainUtil)
        if act != "null()":
            done = True
        return [done, act]
    def work(self, belief):
        """Primary response function of HDC policy
        """
        global_summary = SummaryMapping.globalSummary(belief, domainUtil=self.domainUtil)
        array_slot_summary = SummaryMapping.arraySlotSummary(belief, self.domainUtil)
        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 = SummaryMapping.actionSpecificInformSummary(belief, num_accepted, self.domainUtil)
                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 = DMUtils.add_venue_count(output, belief)
        return output
    def getRequest(self, belief, slot):
        """
        """
        array_slot_summary = SummaryMapping.arraySlotSummary(belief, self.domainUtil)
        summary = array_slot_summary[slot]
        (_, topprob) = summary["TOPTWO"][0]
        (_, secprob) = summary["TOPTWO"][1]

        # if topprob < 0.4 and secprob<= 0.3:
        return True, "request(%s)" % slot
 def getConfirm(self, belief, slot):
     """
     """
     array_slot_summary = SummaryMapping.arraySlotSummary(belief, self.domainUtil)
     summary = array_slot_summary[slot]
     (top_value, top_prob) = summary["TOPTWO"][0]
     (sec_value, sec_prob) = summary["TOPTWO"][1]
     if top_prob > 0:
         return True, 'confirm(%s="%s")' % (slot, top_value)
     return False, "null()"
 def getReqMore(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     #if global_summary['GLOBAL_ACK'] > 0.5 or global_summary['GLOBAL_THANKYOU']>0.5:
     act = DMUtils.getGlobalAction(belief, 'REQMORE', self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
 def getBye(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     if global_summary['GLOBAL_FINISHED'] > 0.5:
         act = DMUtils.getGlobalAction(belief, 'BYE', self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
 def getRestart(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     if global_summary['GLOBAL_RESTART'] > 0.5:
         act = DMUtils.getGlobalAction(belief, 'RESTART', self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
 def getRestart(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     if global_summary["GLOBAL_RESTART"] > 0.5:
         act = DMUtils.getGlobalAction(belief, "RESTART", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
 def getReqMore(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     # if global_summary['GLOBAL_ACK'] > 0.5 or global_summary['GLOBAL_THANKYOU']>0.5:
     act = DMUtils.getGlobalAction(belief, "REQMORE", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
    def getRequest(self, belief, slot):
        '''
        '''
        array_slot_summary = SummaryMapping.arraySlotSummary(
            belief, self.domainUtil)
        summary = array_slot_summary[slot]
        (_, topprob) = summary['TOPTWO'][0]
        (_, secprob) = summary['TOPTWO'][1]

        #if topprob < 0.4 and secprob<= 0.3:
        return True, 'request(%s)' % slot
 def getInformRequested(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     if global_summary["GLOBAL_BYNAME"] > 0.5:
         act = DMUtils.getGlobalAction(belief, "INFORM_REQUESTED", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
 def getBye(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     if global_summary["GLOBAL_FINISHED"] > 0.5:
         act = DMUtils.getGlobalAction(belief, "BYE", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
 def getInformAlternatives(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     if global_summary["GLOBAL_BYALTERNATIVES"] > 0.5:
         act = DMUtils.getGlobalAction(belief, "INFORM_ALTERNATIVES", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
 def getConfirm(self, belief, slot):
     '''
     '''
     array_slot_summary = SummaryMapping.arraySlotSummary(
         belief, self.domainUtil)
     summary = array_slot_summary[slot]
     (top_value, top_prob) = summary['TOPTWO'][0]
     (sec_value, sec_prob) = summary['TOPTWO'][1]
     if top_prob > 0:
         return True, 'confirm(%s="%s")' % (slot, top_value)
     return False, 'null()'
 def getInformAlternatives(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     if global_summary['GLOBAL_BYALTERNATIVES'] > 0.5:
         act = DMUtils.getGlobalAction(belief, 'INFORM_ALTERNATIVES',
                                       self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
    def _updateMactFeat(self, last_feature, lastact):
        '''
        Add features into self.prevstate  - recording actions taken by machine
        :return:
        '''
        features = {}
        if self.turn == 0:
            features['lastInformedVenue'] = ''
            features['informedVenueSinceNone'] = []
            features['lastActionInformNone'] = False
            features['offerHappened'] = False

        else:
            last_system_act = dact.ParseAct(lastact, user=False)

            # lastInformedVenue
            current_informed_venue = agentutils._getCurrentInformedVenue(
                last_system_act)
            if current_informed_venue != '':
                features['lastInformedVenue'] = current_informed_venue
            else:
                features['lastInformedVenue'] = last_feature[
                    'lastInformedVenue']

            # informedVenueSinceNone
            if agentutils._hasType(last_system_act, 'canthelp'):
                self.informedVenueSinceNone = []
            if agentutils._hasTypeSlot(last_system_act, 'offer', 'name'):
                venue = agentutils._getTypeSlot(last_system_act, 'offer',
                                                'name')
                self.informedVenueSinceNone.append(venue)
            features['informedVenueSinceNone'] = self.informedVenueSinceNone

            # lastActionInformNone
            if agentutils._hasType(last_system_act, 'canthelp'):
                features['lastActionInformNone'] = True
            else:
                features['lastActionInformNone'] = False

            # offerhappened
            if agentutils._hasTypeSlot(last_system_act, 'offer', 'name'):
                features['offerHappened'] = True
            else:
                features['offerHappened'] = False

        # inform_info
        features['inform_info'] = []
        for numAccepted in range(1, 6):
            temp = SummaryMapping.actionSpecificInformSummary(
                self.prevbelief, numAccepted, self.domainUtil)
            features['inform_info'] += temp

        self.prevbelief['features'] = features
 def getInformRequested(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     if global_summary['GLOBAL_BYNAME'] > 0.5:
         act = DMUtils.getGlobalAction(belief, 'INFORM_REQUESTED',
                                       self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
    def work(self, belief):
        """Primary response function of HDC policy
        """
        global_summary = SummaryMapping.globalSummary(
            belief, domainUtil=self.domainUtil)
        array_slot_summary = SummaryMapping.arraySlotSummary(
            belief, self.domainUtil)
        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 = SummaryMapping.actionSpecificInformSummary(
                    belief, num_accepted, self.domainUtil)
                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 = DMUtils.add_venue_count(output, belief)
        return output
 def getInformByName(self, belief):
     """
     """
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = "null()"
     if (
         global_summary["GLOBAL_BYCONSTRAINTS"]
         > 0.5  # or global_summary['GLOBAL_BYNAME'] >0 or global_summary['GLOBAL_BYALTERNATIVES'] > 0.5
     ) and global_summary["GLOBAL_COUNT80"] > 3:
         act = DMUtils.getGlobalAction(belief, "INFORM_BYNAME", self.domainUtil)
     if act != "null()":
         done = True
     return done, act
 def getInformByName(self, belief):
     '''
     '''
     global_summary = SummaryMapping.globalSummary(belief, self.domainUtil)
     done = False
     act = 'null()'
     if (global_summary['GLOBAL_BYCONSTRAINTS'] > 0.5 #or global_summary['GLOBAL_BYNAME'] >0 or global_summary['GLOBAL_BYALTERNATIVES'] > 0.5
         ) and\
         global_summary['GLOBAL_COUNT80'] > 3:
         act = DMUtils.getGlobalAction(belief, 'INFORM_BYNAME',
                                       self.domainUtil)
     if act != 'null()':
         done = True
     return done, act
    def _updateMactFeat(self, last_feature, lastact):
        '''
        Add features into self.prevstate  - recording actions taken by machine
        :return:
        '''
        features = {}
        if self.turn == 0:
            features['lastInformedVenue'] = ''
            features['informedVenueSinceNone'] = []
            features['lastActionInformNone'] = False
            features['offerHappened'] = False

        else:
            last_system_act = dact.ParseAct(lastact, user=False)

            # lastInformedVenue
            current_informed_venue = agentutils._getCurrentInformedVenue(last_system_act)
            if current_informed_venue != '':
                features['lastInformedVenue'] = current_informed_venue
            else:
                features['lastInformedVenue'] = last_feature['lastInformedVenue']

            # informedVenueSinceNone
            if agentutils._hasType(last_system_act, 'canthelp'):
                self.informedVenueSinceNone = []
            if agentutils._hasTypeSlot(last_system_act, 'offer', 'name'):
                venue = agentutils._getTypeSlot(last_system_act, 'offer', 'name')
                self.informedVenueSinceNone.append(venue)
            features['informedVenueSinceNone'] = self.informedVenueSinceNone

            # lastActionInformNone
            if agentutils._hasType(last_system_act, 'canthelp'):
                features['lastActionInformNone'] = True
            else:
                features['lastActionInformNone'] = False

            # offerhappened
            if agentutils._hasTypeSlot(last_system_act, 'offer', 'name'):
                features['offerHappened'] = True
            else:
                features['offerHappened'] = False

        # inform_info
        features['inform_info'] = []
        for numAccepted in range(1,6):
            temp =  SummaryMapping.actionSpecificInformSummary(self.prevbelief, numAccepted, self.domainUtil)
            features['inform_info'] += temp
           
        self.prevbelief['features'] = features