def wrapper(self): for intent_name, info in func(self).iteritems(): intent = IntentBuilder(intent_name) if "require" not in info: info["require"] = [] if "optionally" not in info: info["optionally"] = [] if "one of" not in info: info["one of"] = [] for require in info["require"]: intent.require(require) for optionally in info["optionally"]: intent.optionally(optionally) for one_of in info["one of"]: intent.one_of(one_of) intent = intent.build() logger.debug("Adding {} intent through {} plugin".format( intent_name, self.__class__.__name__)) engine_handler.get_engine().register_intent_parser(intent) plugins_handler.set_intent_plugin(intent_name, self.__class__.__name__) return func(self)
def make_intents_struct(self, struct_list): # process new style intent for i18n intents = [] for struct in struct_list: # single language for i_inf in struct['utterances']: # intent info i_name = '{}{}Intent'.format(self.h_prefix, hash_sum(str(i_inf))) builder = IntentBuilder(i_name) for section in i_inf: section = ''.join(ch for ch in section if re.match(r'A-Za-z0-9:\|', ch)) entity_type = self.make_entity_type(section.split(':')[1]) if section.startswith('req:'): builder.require(entity_type) continue elif section.startswith('opt:'): builder.optionally(entity_type) continue elif section.startswith('one:'): entity_types = [ self.make_entity_type(e) for e in section.split(':')[1].split('|') ] builder.one_of(entity_types) continue else: # shouldn't be here self.log.error( 'Something wrong with the struct: {}'.format( struct)) intents.append(builder.build()) return intents