def lang2pattern(cls, lang): j_me = cls.j_yaml() langs_recognizable = HenriqueLocale.lang2langs_recognizable(lang) me_list = [ me for lang in langs_recognizable for me in j_me.get(lang, []) ] rstr = RegexTool.rstr_iter2or(map(re.escape, me_list)) pattern = re.compile(rstr, re.I) return pattern
def pattern_rate_trend(cls): # rstr_idk = RegexTool.rstr_iter2or(map(re.escape, cls.dict_lang2text_idk().values())) rstr_arrows = RegexTool.rstr_iter2or( map(re.escape, Trend.dict_trend2arrow().values())) rstr_rate_trend = RegexTool.join(r"", [r"\d{2,3}", rstr_arrows]) # rstr = r"{}\s*$".format(RegexTool.rstr_iter2or([rstr_idk, rstr_rate_trend])) # rstr = r"{}\s*$".format(rstr_rate_trend) # raise Exception(rstr) pattern = re.compile(RegexTool.rstr2wordbounded(rstr_rate_trend), re.I) return pattern
def texts2pattern(texts): rstr_raw = RegexTool.rstr_iter2or(map(re.escape, texts)) left_bounds = lchain( RegexTool.bounds2suffixed(RegexTool.left_wordbounds(), "\d"), RegexTool.left_wordbounds(), ) right_bounds = RegexTool.right_wordbounds() rstr = RegexTool.rstr2bounded(rstr_raw, left_bounds, right_bounds) logger.debug({ "rstr": rstr, "rstr_raw": rstr_raw, }) return re.compile(rstr, re.I)
def rstr_last_char(cls): rstr_suffix_list = [r"\d", Metricprefix.rstr()] return RegexTool.rstr_iter2or(rstr_suffix_list)
def rstr(cls): return RegexTool.rstr_iter2or(map(re.escape, cls.Value.set()))
def pattern_variation(cls): l = lchain(cls.string_singlequote(), cls.string_doublequote()) rstr = RegexTool.rstr_iter2or(map(re.escape, l)) p = re.compile(rstr) return p
def j_yaml2p_command(cls, j_yaml): h_lang2names = j_yaml.get("default_action_names") rstr = RegexTool.rstr_iter2or(lchain(*list(h_lang2names.values()))) return re.compile("{}$".format(rstr), re.I)
def texts2regex(cls, texts): return RegexTool.rstr_iter2or(map(re.escape, texts))
def rstr(cls): rstr_multidigit = r"[1-9][0-9]+" rstr_onedigit = r"[0-9]" rstr_number = RegexTool.rstr_iter2or([rstr_multidigit, rstr_onedigit]) return rstr_number
def lang2rstr(cls, lang): aliases = cls._lang2dict_alias2codename(lang).keys() return RegexTool.rstr_iter2or( map(lambda x: re.escape(cls.text2norm(x)), aliases))
def rstr_short(cls): h = cls.h_value2str() return RegexTool.rstr_iter2or(h.values())
def rstr(cls): return RegexTool.rstr_iter2or(cls.Value.value_set())