Exemplo n.º 1
0
    def _getInform(self, belief, global_summary, inform_summary):
        act = 'null()'

        count80 = global_summary['GLOBAL_COUNTACCEPTED']
        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

        logger.debug(
            '%d among %d slots are accepted (>=0.8 belief).' %
            (count80,
             Ontology.global_ontology.get_length_system_requestable_slots(
                 self.domainString)))

        count80_logic = count80 >= Ontology.global_ontology.get_length_system_requestable_slots(
            self.domainString)
        if first or second or not discr or count80_logic:
            # If this inform gives either 0 or 1 or we've found everything we can ask about
            logger.debug(
                'Trying to get inform action, have enough accepted slots.')
            logger.debug('Is there no matching entity? %s.' % str(first))
            logger.debug('Is there only one matching entity? %s.' %
                         str(second))
            logger.debug('Can we discriminate more? %s.' % str(discr))
            requested_slots = SummaryUtils.getRequestedSlots(belief)

            if len(requested_slots) > 0 and offer_happened:
                logger.debug('Getting inform requested action.')
                act = PolicyUtils.getGlobalAction(
                    belief, 'INFORM_REQUESTED', domainString=self.domainString)
            else:
                logger.debug(
                    'Getting inform exact action with %d accepted slots.' %
                    count80)
                act = PolicyUtils.getInformAction(
                    count80, belief, domainString=self.domainString)

        if act != 'null()':
            return True, act
        return False, act
Exemplo n.º 2
0
def getGlobalAction(belief, globalact, domainString):
    '''**Method for global action:** returns action 

    :param belief: full belief state
    :type belief: dict
    :param globalact: - str of globalActionName, e.g. 'INFORM_REQUESTED'
    :type globalact: int
    :param domainString: domain tag
    :type domainString: str
    :returns: (str) action
    '''

    # First get the name for the name goal.
    topvalue, topbelief = SummaryUtils.getTopBelief(belief['beliefs']['name'])
    toptwo, _ = SummaryUtils.getTopBeliefsExcludingNone(belief['beliefs']['name'])
    if topvalue == '**NONE**' or topvalue == 'dontcare' or topbelief < 0.8:
        topnamevalue = ''
    else:
        topnamevalue = toptwo[0][0]

    lastInformedVenue = belief['features']['lastInformedVenue']
    informedVenueSinceNone = belief['features']['informedVenueSinceNone']
    acceptanceList = SummaryUtils.getTopBeliefs(belief, domainString=domainString)
    inform_threshold = 0
    if Settings.config.has_option("policy", "informthreshold"):
        inform_threshold = float(Settings.config.get('policy','informthreshold'))
    if inform_threshold > 0:
        acceptanceList80 = SummaryUtils.getTopBeliefs(belief, inform_threshold, domainString=domainString)
    else:
        acceptanceList80 = acceptanceList
    requestedSlots = SummaryUtils.getRequestedSlots(belief)

    # logger.debug('topnamevalue = %s, lastInformedVenue = %s' % (topnamevalue, lastInformedVenue))
    if topnamevalue == '' and lastInformedVenue != '':
        # logger.debug('topnamevalue is None, but copy lastInformedVenue')
        topnamevalue = lastInformedVenue


    if globalact == 'INFORM_REQUESTED':
        if topnamevalue != '':
            return _getInformRequestedSlots(acceptanceList80, requestedSlots, topnamevalue, domainString)
        else:
            return _getInformRequestedSlots(acceptanceList80, requestedSlots, 'none', domainString)
    elif globalact == 'INFORM_ALTERNATIVES':
        #if lastInformedVenue == '':
        #    print 'Cant inform alternatives no last informed venue'
        #    return 'null()'
        #else:
        return _getInformAlternativeEntities(acceptanceList, acceptanceList80, informedVenueSinceNone, domainString)
    elif globalact == 'INFORM_MORE': #ic340: is this ever used?
        if len(informedVenueSinceNone) > 0 and topnamevalue != '':
            return _getInformMoreEntity(topnamevalue, domainString)
        else:
            return _getInformMoreEntity('none', domainString)
    elif globalact == 'INFORM_BYNAME':
        return _getInformAlternativeEntities(acceptanceList, acceptanceList80, [], domainString)
    elif globalact == 'INFORM_REPEAT':
        return 'null()'
    elif globalact == 'REQMORE':
        if lastInformedVenue != '':
            return 'reqmore()'
        else:
            return 'null()'
    elif globalact == 'BYE':
        return 'bye()'
    elif globalact == 'RESTART':
        return 'null()'
    else:
        logger.warning('Invalid global summary action name: ' + globalact)
        return 'null()'