예제 #1
0
    def __init__(self, domain: JSONLookupDomain, parameters=None):
        self.domain = domain
        self.parameters = parameters or {}

        # cache inform and request slots
        # make sure to copy the list (shallow is sufficient)
        self.inf_slots = sorted(list(domain.get_informable_slots())[:])
        # make sure that primary key is never a constraint
        if self.domain.get_primary_key() in self.inf_slots:
            self.inf_slots.remove(self.domain.get_primary_key())

        # TODO sometimes ask for specific primary key with very small probability (instead of any other constraints?) # pylint: disable=line-too-long

        self.inf_slot_values = {}
        for slot in self.inf_slots:
            self.inf_slot_values[slot] = sorted(
                domain.get_possible_values(slot)[:])
        self.req_slots = sorted(domain.get_requestable_slots()[:])
        # self.req_slots_without_informables = sorted(list(
        #     set(self.req_slots).difference(self.inf_slots)))
        # make sure that primary key is never a request as it is added anyway
        if self.domain.get_primary_key() in self.req_slots:
            self.req_slots.remove(self.domain.get_primary_key())

        self.constraints = []
        self.requests = {}
        self.excluded_inf_slot_values = {}
        self.missing_informs = []
예제 #2
0
def _create_inform_json(domain: JSONLookupDomain, template: RegexFile):
    inform_regex_json = {}
    for slot in domain.get_informable_slots():
        inform_regex_json[slot] = {}
        for value in domain.get_possible_values(slot):
            inform_act = UserAct(act_type=UserActionType.Inform,
                                 slot=slot,
                                 value=value)
            inform_regex_json[slot][value] = template.create_regex(inform_act)
    return inform_regex_json
예제 #3
0
파일: goal.py 프로젝트: zhiyin121/adviser
    def __init__(self, domain: JSONLookupDomain, parameters=None):
        """
        The class representing a goal, therefore containing requests and constraints.

        Args:
            domain (JSONLookupDomain): The domain for which the goal will be instantiated.
                It will only work within this domain.
            parameters (dict): The parameters for the goal defined by a key=value mapping: 'MinVenues'
                (int) allows to set a minimum number of venues which fulfill the constraints of the goal,
                'MinConstraints' (int) and 'MaxConstraints' (int) set the minimum and maximum amount of
                constraints respectively, 'MinRequests' (int) and 'MaxRequests' (int) set the minimum and
                maximum amount of requests respectively and 'Reachable' (float) allows to specify how many
                (in percent) of all generated goals are definitely fulfillable (i.e. there exists a venue
                for the current goal) or not (doesn't have to be fulfillable). Although the parameter
                'Reachable' equals 1.0 implicitly states that 'MinVenues' equals 1 or more, the
                implementation looks different, is more efficient and takes all goals into consideration
                (since 'Reachable' is a float (percentage of generated goals)). On the other hand, setting
                'MinVenues' to any number bigger than 0 forces every goal to be fulfillable.

        """
        self.domain = domain
        self.parameters = parameters or {}

        # cache inform and request slots
        # make sure to copy the list (shallow is sufficient)
        self.inf_slots = sorted(list(domain.get_informable_slots())[:])
        # make sure that primary key is never a constraint
        if self.domain.get_primary_key() in self.inf_slots:
            self.inf_slots.remove(self.domain.get_primary_key())

        # TODO sometimes ask for specific primary key with very small probability (instead of any other constraints?) # pylint: disable=line-too-long

        self.inf_slot_values = {}
        for slot in self.inf_slots:
            self.inf_slot_values[slot] = sorted(
                domain.get_possible_values(slot)[:])
        self.req_slots = sorted(domain.get_requestable_slots()[:])
        # self.req_slots_without_informables = sorted(list(
        #     set(self.req_slots).difference(self.inf_slots)))
        # make sure that primary key is never a request as it is added anyway
        if self.domain.get_primary_key() in self.req_slots:
            self.req_slots.remove(self.domain.get_primary_key())

        self.constraints = []
        self.requests = {}
        self.excluded_inf_slot_values = {}
        self.missing_informs = []
예제 #4
0
    def __init__(self,
                 domain: JSONLookupDomain = None,
                 subgraph=None,
                 logger: DiasysLogger = DiasysLogger()):
        super(MLBST, self).__init__(domain, subgraph, logger=logger)
        self.path_to_data_folder = os.path.join(os.path.realpath(os.curdir),
                                                "modules", "bst", "ml")
        self.primary_key = domain.get_domain_name()

        self.data_mappings = DSTC2Data(
            path_to_data_folder=self.path_to_data_folder,
            preprocess=False,
            load_train_data=False)

        self.inf_trackers = {}
        self.req_trackers = {}

        for inf_slot in domain.get_informable_slots():
            self._load_inf_model(inf_slot)
        for req_slot in domain.get_requestable_slots():
            self._load_req_model(req_slot)
예제 #5
0
파일: nlu.py 프로젝트: zhiyin121/adviser
    def __init__(self, domain: JSONLookupDomain, logger: DiasysLogger = DiasysLogger(),
                 language: Language = None):
        """
        Loads
            - domain key
            - informable slots
            - requestable slots
            - domain-independent regular expressions
            - domain-specific regualer espressions

        It sets the previous system act to None

        Args:
            domain {domain.jsonlookupdomain.JSONLookupDomain} -- Domain
        """
        Service.__init__(self, domain=domain)
        self.logger = logger

        self.language = language if language else Language.ENGLISH

        # Getting domain information
        self.domain_name = domain.get_domain_name()
        self.domain_key = domain.get_primary_key()

        # Getting lists of informable and requestable slots
        self.USER_INFORMABLE = domain.get_informable_slots()
        self.USER_REQUESTABLE = domain.get_requestable_slots()

        # Getting the relative path where regexes are stored
        self.base_folder = os.path.join(get_root_dir(), 'resources', 'nlu_regexes')

        # Setting previous system act to None to signal the first turn
        # self.prev_sys_act = None
        self.sys_act_info = {
            'last_act': None, 'lastInformedPrimKeyVal': None, 'lastRequestSlot': None}

        self.language = Language.ENGLISH
        self._initialize()
예제 #6
0
파일: nlu.py 프로젝트: wendywtchang/adviser
    def __init__(self,
                 domain: JSONLookupDomain,
                 subgraph=None,
                 logger: DiasysLogger = DiasysLogger(),
                 language: Language = None):
        """
        Loads
            - domain key
            - informable slots
            - requestable slots
            - domain-independent regular expressions
            - domain-specific regualer espressions

        It sets the previous system act to None

        Args:
            domain {domain.jsonlookupdomain.JSONLookupDomain} -- Domain
            subgraph  {[type]} -- [see modules.Module] (default: {None})
            logger:
        """
        super(HandcraftedNLU, self).__init__(domain, None, logger=logger)

        self.language = language if language else Language.ENGLISH

        # Getting domain information
        self.domain_name = domain.get_domain_name()
        self.domain_key = domain.get_primary_key()

        # Getting lists of informable and requestable slots
        self.USER_INFORMABLE = domain.get_informable_slots()
        self.USER_REQUESTABLE = domain.get_requestable_slots()

        # Getting the relative path where regexes are stored
        self.base_folder = os.path.join(get_root_dir(), 'resources', 'regexes')

        # Setting previous system act to None to signal the first turn
        self.prev_sys_act = None