def init_slots(self): """skill name :return: <dict> slots dict """ return { Tag.name(): Tag(), TimeInterval.name(): TimeInterval(), Company.name(): Company() }
def extract(self, context): """ :param context: context["query"] :return: <dict of list> {"TimeInterval": ["", ""]} """ rst = {} ext_time = self.ner_time.extract(context) ext_location = self.ner_loc.extract(context) ext_company = self.ner_company.extract(context) ext_tag = self.ner_tag.extract(context) if ext_time is not None: rst[TimeInterval.name()] = ext_time logger.debug("extract time %s" % " ".join(ext_time)) if ext_location is not None: rst[Location.name()] = ext_location logger.debug("extract loc {}".format(ext_location)) if ext_company is not None: rst[Company.name()] = ext_company logger.debug("extract company %s" % " ".join(ext_company)) if ext_tag is not None: rst[Tag.name()] = ext_tag # logger.debug("extract tag %s" % " ".join(ext_tag)) return rst
def extract(self, context): entities = process.extract(context["query"], self.keywords) print(entities) entities = filter(lambda x: x[1] >= self.threshold, entities) entities = sorted(entities, key=lambda x: x[1] + len(x[0]) / 10, reverse=True) entities = list(map(lambda x: Tag(TAGMAP[x[0]]), entities)) if len(entities) == 0: return None return entities[0]
def transform(self, context): """ :param context: context['query'] :return: dict of list [{'end':'2018-06-13','start':'2018-06-13'}] """ rst = {} trans_time = self.ner_time.transform(context) trans_location = self.ner_loc.transform(context) trans_company = self.ner_company.transform(context) trans_tag = self.ner_tag.transform(context) if trans_time is not None: rst[TimeInterval.name()] = trans_time if trans_location is not None: rst[Location.name()] = trans_location if trans_company is not None: rst[Company.name()] = trans_company if trans_tag is not None: rst[Tag.name()] = trans_tag return rst
def init_slots(self): return {TimeInterval.name(): TimeInterval(), Tag.name(): Tag(), Company.name(): Company()}