def ex_date_parse(key, cnt, comp, ctx: cla_meta_intf): from dateparser import parse parse_r = parse(cnt, languages=[ctx.lang]) if parse_r is not None: ctx.add_result(extractor, comp, key, str(parse_r)) return True return False
def ex_date_search(key, cnt: Text, comp, ctx: cla_meta_intf): from dateparser.search import search_dates search_r = search_dates(cnt, languages=[ctx.lang]) if search_r is not None: ctx.add_result(extractor, comp, key, [str(r) for r in search_r]) return True return False
def ex_feats(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf): from sagas.nlu.features import get_feats_map domain, path = key.split(':') result = get_feats_map(ctx.sents, ctx.lang, domain, path) if result: ctx.add_result(extractor, comp, key, result) return True return False
def ex_dims(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf, dim): from sagas.nlu.inspectors import query_duckling resp = query_duckling(cnt, ctx.lang) # print('*************', cnt, ctx.lang, resp) values = [d for d in resp['data'] if d['dim'] == dim] if len(values) > 0: ctx.add_result(extractor, comp, key, values) return True return False
def ex_translit(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf): from sagas.nlu.transliterations import translits if translits.is_available_lang(ctx.lang): tval = translits.translit(cnt, ctx.lang) # tval=tval.replace('[UNK]', '').strip() ctx.add_result(extractor, comp, key, tval) else: ctx.add_result(extractor, comp, key, cnt) return True
def ex_rasa(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf): from sagas.conf.conf import cf from sagas.nlu.rasa_procs import invoke_nlu endpoint = cf.ensure('nlu_multilang_servant') result = invoke_nlu(endpoint, ctx.lang, "current", ctx.sents) # print('*******', result) if result != None: ctx.add_result(extractor, comp, 'sents', result) return True return False
def ex_ner(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf): data = {"sents": ctx.sents if key == '_' else cnt} route = f'spacy/{ctx.lang}' if ctx.lang in ('zh', 'ru', 'ja', 'id') else ctx.lang response = requests.post(f'http://localhost:1700/ner/{route}', json=data) if response.status_code == 200: result = response.json() if result: ctx.add_result(extractor, comp, key, result) return True return False
def ex_chunk(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf, clo): from sagas.nlu.uni_chunks import get_chunk from sagas.nlu.ruleset_procs import list_words, cached_chunks from sagas.conf.conf import cf # get_chunk(f'verb_domains', 'xcomp/obj', lambda w: w.upos) chunks = cached_chunks(ctx.sents, ctx.lang, cf.engine(ctx.lang)) domain, path = key.split(':') result = get_chunk(chunks, f'{domain}_domains' if domain != 'predicts' else domain, path, clo=clo) logger.debug(f"extract chunk: {domain}, {path}, {result}") if len(result) > 0: ctx.add_result(extractor, comp, key, result) return True return False
def ex_plain(key: Text, cnt: Text, comp: Text, ctx: cla_meta_intf): ctx.add_result(extractor, comp, key, cnt) return True