Ejemplo n.º 1
0
def arraySlotSummaryRel(belief, domainString):
    '''
    Gets the summary vector for goal slots, including the top probabilities, entropy, etc.

    :param belief: dict representing the full belief state
    :param domainString: string representing the domain
    :return: (dict) of slot goal summaries
    '''
    summary = {}
    slots = Ontology.global_ontology.get_common_slots_for_all_types(
        domainString)

    for domain in slots:
        for s in slots[domain]:
            slot = domain + '_' + s
            summary[slot] = {}
            slot_belief = belief['beliefs'][slot]
            summary[slot]['TOPHYPS'], summary[slot][
                'ISTOPNONE'] = SummaryUtils.getTopBeliefsExcludingNone(
                    belief['beliefs'][slot])
            belief_dist = slot_belief.values()
            summary[slot]['ENTROPY'] = entropy(belief_dist)
            summary[slot][
                'ISREQUESTTOP'] = belief['beliefs']['requested'][slot] > 0.5

    return summary
Ejemplo 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()'