Esempio n. 1
0
    def clean(self, sys_act=None):
        """
        """
        #TODO - deal with duplicates, probabilities, others?
        tempActs = {}

        #first add context to user acts
        for act in self.semanticActs:
            [act
             ] = contextUtils._add_context_to_user_act(sys_act, [[act, 1.0]],
                                                       self.domainTag)
            act = act[0]
            intent, slotValues = self._parseDialogueAct(act)
            if intent not in tempActs:
                tempActs[intent] = slotValues
            else:
                for slot in slotValues:
                    if slot in tempActs[intent]:
                        if slotValues[slot] != tempActs[intent][slot]:
                            logger.warning(
                                'Sematic decoding of input lead to different interpretations within one hypothesis. Slot {} has values {} and {}.'
                                .format(slot, slotValues[slot],
                                        tempActs[intent][slot]))
                    else:
                        tempActs[intent][slot] = slotValues[slot]
        #x
        hypos = []
        for intent in tempActs:
            if len(tempActs[intent]):
                (key, value) = tempActs[intent].items()[0]
                if value is not None:
                    hypos.append('{}({})'.format(
                        intent,
                        ','.join('%s=%s' % (key, value)
                                 for (key,
                                      value) in tempActs[intent].items())))
                else:
                    hypos.append('{}({})'.format(
                        intent,
                        ','.join('%s' % (key)
                                 for (key,
                                      value) in tempActs[intent].items())))
            else:
                logger.warning("intent {} found in input without arguments")
        self.semanticActs = "|".join(hypos)
 def simulate_add_context_to_user_act(self, sys_act, user_acts, domainTag):
     '''
     NB: only for Simulate.py
     
     While for simulation no semantic decoding is needed, context information needs to be added in some instances. This is done with this method.
     
     :param sys_act: the last system act
     :type sys_act: str
     :param user_acts: user act hypotheses
     :type user_acts: list
     :param domainTag: the domain of the dialogue
     :type domainTag: str
     '''
     # simulate - will only pass user_act, and we will return contextual user act
     self.active_domain = domainTag  # this is required below in checking binary slots of given domain
     hyps = contextUtils._add_context_to_user_act(
         sys_act, hyps=user_acts, active_domain=self.active_domain)
     return hyps  # just the act
Esempio n. 3
0
    def simulate_add_context_to_user_act(self, sys_act, user_acts, eType):
        '''
        NB: only for Simulate.py
        
        While for simulation no semantic decoding is needed, context information needs to be added in some instances. This is done with this method.
        
        :param sys_act: the last system act
        :type sys_act: str
        :param user_acts: user act hypotheses
        :type user_acts: list
        :param domainTag: the domain of the dialogue
        :type domainTag: str
        '''
        # simulate - will only pass user_act, and we will return contextual user act

        hyps = contextUtils._add_context_to_user_act(sys_act.to_string_plain(),
                                                     hyps=user_acts,
                                                     active_domain=eType)
        return hyps  # just the act
Esempio n. 4
0
File: SemI.py Progetto: WowCZ/strac
    def decode(self, ASR_obs, sys_act, domainTag, turn=None):
        '''
        The main method for semantic decoding. It takes the ASR input and returns a list of semantic interpretations. To decode, the task is delegated to the respective domain semantic decoder
        
        :param ASR_obs: ASR hypotheses
        :type ASR_obs: list
        :param sys_act: is the system action prior to collecting users response in obs.
        :type sys_act: str
        :param domainTag: is the domain we want to parse the obs in
        :type domainTag: str
        :param turn: the turn id, this parameter is optional
        :type turn: int
        :return: None
        '''

        # use the correct domain:
        self.active_domain = domainTag  # used down call chain in adding context
        self._ensure_booted(domainTag)

        # --------
        # explore how to clean IBM asr - "i dont care" problem ...
        for i in range(len(ASR_obs)):
            was = ASR_obs[i][0]
            fix = [
                str(c) for c in was if c.isalpha() or c.isspace() or c == "'"
                or c != "!" or c != "?"
            ]  # slow way - initial fix #lmr46 06/09/16 this filtering filters question marks that are important!!!! syj requirement
            res = ''.join(fix)
            ASR_obs[i] = (res.rstrip(), ASR_obs[i][1])
        #---------------------------------------------------

        # Additional argument turn as described above
        hyps = self.semiManagers[domainTag].decode(ASR_obs, sys_act, turn=turn)
        logger.info(hyps)
        # add context if required
        hyps = contextUtils._add_context_to_user_act(sys_act, hyps,
                                                     self.active_domain,
                                                     self.ontology)
        return hyps