예제 #1
0
    def _addRelationToAgenda(self, targetDomain):
        # made sure by calling the method that targetDomain is not part of visited_domains

        tGoal = self.simUserManagers[targetDomain].um.goal
        commonSlotsAndRelations = dict()
        # for each domain which we have already visited:
        for vdomain in self.visited_domains:
            #    compare goals, check whether slots are the same
            vGoal = self.simUserManagers[vdomain].um.goal
            commonSlotsAndRelations[
                vdomain] = self._getCommonSlotsAndRelations(
                    vGoal.constraints,
                    tGoal.constraints)  # currently only equals

        tAgenda = self.simUserManagers[targetDomain].um.hdcSim.agenda

        for vdomain in commonSlotsAndRelations:
            if len(commonSlotsAndRelations[vdomain]):
                for slot in commonSlotsAndRelations[vdomain]:
                    #    if slots are the same:
                    if commonSlotsAndRelations[vdomain][slot] == '=':
                        #        replace entry in agenda
                        for i in range(len(tAgenda.agenda_items)):
                            if tAgenda.agenda_items[i].contains_slot(slot):
                                newAct = DActEntity.DiaActEntity()
                                newAct.act = tAgenda.agenda_items[i].act
                                newAct.items = [
                                    DActEntity.DactItemEntity(
                                        slot, '=', slot, targetDomain, vdomain)
                                ]
                                tAgenda.agenda_items[i] = newAct
                                return

        pass
예제 #2
0
    def act_on(self, sys_act):
        """ First produce a single semantic act from the simulated user. Then create from it a list of semantic hypotheses which
        include simulated errors. 
        """
        user_act, user_actsDomain = self._user_act(sys_act)
        hyps = self._confuse_user_act_and_enforce_null(user_act,
                                                       user_actsDomain)

        # add domains as entity to user act
        user_act = DActEntity.DiaActEntity(user_act, user_actsDomain)
        hyps = [DActEntity.DiaActEntity(h, user_actsDomain) for h in hyps]
        user_actsDomain = "TownInfo"

        return user_act, user_actsDomain, hyps
예제 #3
0
    def act_on(self, state):
        '''
        Main policy method: mapping of belief state to system action.
        
        This method is automatically invoked by the agent at each turn after tracking the belief state.
        
        May initially return 'hello()' as hardcoded action. Keeps track of last system action and last belief state.  
        
        :param state: the belief state to act on
        :type state: :class:`~utils.DialogueState.DialogueState`
        :param hyps: n-best-list of semantic interpretations
        :type hyps: list
        :returns: the next system action of type :class:`~utils.DiaAct.DiaAct`
        '''
        beliefstate = state.getFocusBelief()

        if self.lastSystemAction is None and self.startwithhello:
            _systemAct = 'hello()'
        else:
            _systemAct = self.nextAction(beliefstate)
        self.lastSystemAction = _systemAct
        self.prevbelief = beliefstate

        systemAct = DActEntity.DiaActEntity(_systemAct, state.entityFocus)
        return systemAct
예제 #4
0
def _add_context_to_user_act(sys_act, hyps, active_domain):
    '''
    Context information is added to the detected user input, eg affirm() is transformed to inform(slot=value)
    
    Note: this does eventually depend on the current domain we assume we are operating in (self.active_domain)
    
    :param sys_act: system dialogue act
    :type sys_act: str
    :param hyps: hypothesis
    :type hyps: list
    :return:
    '''

    logger.info('Possibly adding context to user semi hyps: %s' % hyps)
    if not len(hyps) or sys_act is None:
        return hyps
    # if negated -- only deal with this for now if it pertains to a binary slot. dont have an act for
    # "i dont want indian food" for example
    new_hyps = []
    for hyp in hyps:
        if hyp.to_string_plain() in ['affirm()', 'negate()']:
            user_act = hyp.to_string_plain()
            user_act = DActEntity.DiaActEntity(
                _convert_yes_no(sys_act, user_act, active_domain))
            user_act.P_Au_O = hyp.P_Au_O
            new_hyps.append(user_act)
        else:
            new_hyps.append(hyp)
    return new_hyps
예제 #5
0
 def _user_act(self, sys_act):
     '''Produces the next user semantic act from the simulated user. Also returns the domain that the act came from 
     --> which avoids doing topictracking during simulate
     '''
     # TODO - this is just a start. lots needs thinking about here.
     # -- needs to return the current simulation domain explictly for now
     # return dstring too -  use this information for error simulation.
     logger.debug('simulated users uncompleted domains:' +
                  str(self.uncompleted_domains))
     for dstring in self.using_domains:
         if dstring in self.uncompleted_domains:
             if len(self.visited_domains
                    ) and dstring not in self.visited_domains:
                 #self._addRelationToAgenda(dstring)
                 pass
             user_act = self.simUserManagers[dstring].act_on(sys_act)
             if 'bye(' in user_act.to_string():
                 sys_act = DActEntity.DiaActEntity('hello()')
                 self.uncompleted_domains.remove(dstring)
                 if len(self.uncompleted_domains):
                     continue
                 else:
                     break
             else:
                 self.visited_domains.add(dstring)
                 break
     return user_act, dstring
예제 #6
0
    def act_on(self, dstring, state):
        '''
        Main policy method which maps the provided belief to the next system action. This is called at each turn by :class:`~Agent.DialogueAgent`
        
        :param dstring: the domain string unique identifier.
        :type dstring: str
        :param belief: the belief state the policy should act on
        :type belief: dict
        :returns: the next system action
        '''
        domainstate = state.domainStates[dstring]

        etype = domainstate.entityFocus

        if etype == dstring:
            domainstate = state

        if self.domainPolicies[etype] is None:
            self.bootup(etype)

        if self.committees[etype] is not None:
            _systemAct = self.committees[dstring].act_on(state=domainstate,
                                                         domainInControl=etype)
        else:
            _systemAct = self.domainPolicies[etype].act_on(state=domainstate)

        systemAct = DActEntity.DiaActEntity(_systemAct, etype)

        return systemAct
예제 #7
0
 def add_const_rel(self, eType1, slot1, eType2, slot2, negate=False):
     """
     """
     if not negate:
         op = '='
     else:
         op = '!='
     item = dact.DactItemEntity(slot1, op, slot2, eType1, eType2)
     self.constraints.append(item)
예제 #8
0
 def add_const(self, eType, slot, value, negate=False):
     """
     """
     if not negate:
         op = '='
     else:
         op = '!='
     item = dact.DactItemEntity(slot, op, value, eType)
     self.constraints.append(item)
예제 #9
0
def ParseActRel(raw_act_text, user=True):
    if isinstance(raw_act_text, str):
        final = []
        for act_text in raw_act_text.split("|") :
            try:
                final += _ParseActRel(DActEntity.DiaActEntity(act_text), user=user)
            except RuntimeError:
                pass # add nothing to final if junk act recieved
        return final
    else: #assume raw_act_text is subclass of DAct
        return _ParseActRel(raw_act_text, user=user)
예제 #10
0
    def act_on(self, state):
        '''
        Main policy method: mapping of belief state to system action.
        
        This method is automatically invoked by the agent at each turn after tracking the belief state.
        
        May initially return 'hello()' as hardcoded action. Keeps track of last system action and last belief state.  
        
        :param state: the belief state to act on
        :type state: :class:`~utils.DialogueState.DialogueState`
        :param hyps: n-best-list of semantic interpretations
        :type hyps: list
        :returns: the next system action of type :class:`~utils.DiaAct.DiaAct`
        '''
        # first get belief of entity in focus
#         entity_beliefstate = state.getEntity(state.entityFocus).belief
        entity_beliefstate = state.getMergedBelief(state.entityFocus,newOne = True, getConflict = False)
        master_beliefstate = state.getMergedBelief(state.entityFocus,newOne = True, getConflict = True)
#         teststate = state.getMergedBelief(state.entityFocus,True)
#         
#         if entity_beliefstate != teststate:
#             for slot in teststate['beliefs']:
#                 if teststate['beliefs'][slot] != entity_beliefstate['beliefs'][slot]:
#                     logger.error('States differ. old: {} new: {}'.format(entity_beliefstate['beliefs'][slot],teststate['beliefs'][slot]))
        # then update db features using merging rule
        entity_beliefstate['features']['inform_info'] = self._updateDBfeatures(state.getMergedBelief(state.entityFocus,False),state.entityFocus)
        master_beliefstate['features']['inform_info'] = self._updateDBfeatures(state.getMergedBelief(state.entityFocus,False),state.entityFocus)
        
        # now get belief of relation
        relation_beliefs = state.getExtendedRelationBeliefs(state.entityFocus)
        for rel in relation_beliefs:
            if 'features' not in relation_beliefs[rel]:
                relation_beliefs[rel]['features'] = dict()
            relation_beliefs[rel]['features']['inform_info'] = entity_beliefstate['features']['inform_info']
        
        if self.lastSystemAction is None and self.startwithhello:
            _systemAct = 'hello()'
        else:
            _systemAct = self.nextAction(entity_beliefstate,relation_beliefs,state.entityFocus,master_beliefstate)
        
        self.lastSystemAction = _systemAct
        
        # not needed as all sub-policies should record their own stuff
#         self.prevbelief = beliefstate
        
        systemAct = DActEntity.DiaActEntity(_systemAct, state.entityFocus)
        return systemAct