def integrate_gloss(word): cs = word["contents"] if has(cs, "大意"): glossy = hqueryx(cs, "大意") if has(cs, "gloss"): gloss = hqueryx(cs, "gloss") if glossy["text"] not in gloss["text"].split(", "): gloss["text"] += ", " + glossy["text"] else: cs.append(otm.content("gloss", glossy["text"])) del cs[hqueryi(cs, "大意")] return word
def splitnotes(word): cs = word["contents"] if has(cs, "notes"): notes = hqueryx(cs, "notes")["text"] return splitnotes_(notes) else: return []
def delete_emptynotes(word): ''' 空白記号のみの notes を消去。 ''' cs = word["contents"] if has(cs, "notes") and re.search(r'^\s*$', hqueryx(cs, "notes")["text"]): del cs[hqueryi(cs, "notes")] return word
def add_relations_for_multi(task_words, entry_dict): ''' r"{[a-zA-Z']}" に該当する単語のうち、エントリーのあるものだけを relations に加える。 "ja" の場合「・関連語」も対象にする。 ''' regex = r"\{[a-zA-Z']+\}" #entry_dict = entry_dict.copy() for word in task_words: cs = word["contents"] _ls = [] if has(cs, "notes"): _ls = re.findall(regex, hqueryx(cs, "notes")["text"]) if has(cs, "関連語"): _ls += re.findall(regex, hqueryx(cs, "関連語")["text"]) _ls = [re.sub(r'^[^a-zA-Z]+', '', re.sub(r'[^a-zA-Z]+$', '', e)) for e in _ls] relations = [] for rel in _ls: for entry in entry_dict[rel[0]]: if entry["form"] == rel: relations.append(otm.relation("", entry)) break word["relations"] = relations return task_words
def goodnotes(word): cs = word["contents"] if has(cs, "notes"): after = splitnotes(word) hqueryx(cs, "notes")["text"] = "" for elem in after: if isinstance(elem, dict): keys = ["大意", "読み方", "語呂合わせ", "関連語"] for k in keys: if k in elem: cs.append({"title":k, "text":elem[k]}) else: hqueryx(cs, "notes")["text"] += elem + " " example_extract(word) return word