Last active
February 16, 2023 12:29
-
-
Save Xifax/d4a86b0d091824c27e65fd595156fcdc to your computer and use it in GitHub Desktop.
Quick and dirty cleanup script for Anki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Scan and remove Anki notes from specified decks. | |
Run from '.../Anki2/User 1/this_script.py' | |
Resources in ./jlpt/* | |
15000k | |
https://github.com/hingston/japanese | |
JLPT | |
https://gist.github.com/nakaly/c2c855766ce1661e11396b09760b9598 | |
""" | |
import sys | |
import tqdm | |
import string | |
import re | |
import csv | |
import pprint | |
import pathlib | |
# import MeCab | |
from wanakana import is_kana, strip_okurigana | |
from fugashi import Tagger | |
from anki.collection import Collection | |
deck_names = [ | |
"🥝Pausado::Games", | |
"🥝Pausado::Games::Cyberpunk 2077", | |
"🥝Pausado::Games::Witcher 3", | |
"🥝Pausado::Complete 10k", | |
] | |
col = Collection("./collection.anki2") | |
# print(col.decks.all_names()) | |
# wakati = MeCab.Tagger("-Owakati") | |
tagger = Tagger("-Owakati") | |
notes_to_remove = [] | |
# Create word list from csv | |
ignore_words = [] | |
# with open("jlpt/15000.custom", "r") as f: | |
# reader = csv.reader(f, delimiter=",") | |
# pre_list = [r[0] for r in reader] | |
# ignore_words.extend(pre_list[:5000]) | |
with open("jlpt/user.custom", "r") as f: | |
reader = csv.reader(f, delimiter=",") | |
ignore_words.extend([r[0] for r in reader]) | |
with open("jlpt/kore.custom", "r") as f: | |
reader = csv.reader(f, delimiter=",") | |
ignore_words.extend([r[7] for r in reader]) | |
files = pathlib.Path("jlpt").glob("*.csv") | |
for file_name in files: | |
with open(file_name, "r") as f: | |
reader = csv.reader(f, delimiter=",") | |
ignore_words.extend([r[1] for r in reader]) | |
ignore_words = list(set(ignore_words)) | |
# print(len(ignore_words)) | |
semi_ignored_words = [] | |
# for card_id in col.find_cards(query="deck:🥝Pausado::Games")[:10]: | |
# for card_id in col.find_cards(query="deck:🥝Pausado::Games"): | |
# for card_id in tqdm.tqdm(col.find_cards(query="deck:🥝Pausado::Games")): | |
# card = col.get_card(card_id) | |
# note = card.note() | |
# expression = note.items()[0] | |
# expression = re.sub(r"[^\w\s]", "", expression[1]) | |
# words = [w.feature.lemma for w in tagger(expression)] | |
# filtered = [w for w in words if not is_kana(w)] | |
# filtered = [w for w in filtered if w] | |
# filtered = [w for w in filtered if "-" not in w] | |
# filtered = [w for w in filtered if not set(w) & set(string.ascii_letters)] | |
# has_new_words = [w for w in filtered if w not in ignore_words] | |
# if has_new_words: | |
# semi_ignored_words.extend(has_new_words) | |
# if not has_new_words: | |
# notes_to_remove.append(note.id) | |
for card_id in tqdm.tqdm(col.find_cards(query='"deck:🥝Pausado::Complete 10k"')): | |
card = col.get_card(card_id) | |
note = card.note() | |
# pprint.pprint(note.items()) | |
kanji, expression = note.items()[1][1], note.items()[14][1] | |
expression = re.sub(r"<.*?>", "", expression) | |
expression = re.sub(r"\[.*?\]", "", expression) | |
expression = re.sub(r" ", "", expression) | |
expression = re.sub(r"[^\w\s]", "", expression) | |
words = [w.feature.lemma for w in tagger(expression)] | |
filtered = [w for w in words if not is_kana(w)] | |
filtered = [w for w in filtered if w] | |
filtered = [w for w in filtered if "-" not in w] | |
filtered = [w for w in filtered if not set(w) & set(string.ascii_letters)] | |
has_new_words = [w for w in filtered if w not in ignore_words] | |
if has_new_words: | |
semi_ignored_words.extend(has_new_words) | |
if not has_new_words: | |
notes_to_remove.append(note.id) | |
print(len(notes_to_remove)) | |
res = col.remove_notes(notes_to_remove) | |
print(res) | |
# from collections import Counter | |
# pprint.pprint(Counter(semi_ignored_words)) | |
# pprint.pprint(set(semi_ignored_words)) | |
col.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
入り口 | |
C | |
CC | |
D | |
DAISY | |
M | |
MIG | |
MOX | |
RAC | |
T | |
VAL | |
Y | |
dob | |
其の | |
何事 | |
何人 | |
出 | |
出し | |
化 | |
化け物 | |
北方 | |
医 | |
匿う | |
十字 | |
呪い | |
呪う | |
儀式 | |
此処 | |
御前 | |
貴方 | |
達 | |
糞 | |
此方 | |
良く | |
怪物 | |
彼奴 | |
此奴 | |
野郎 | |
剣 | |
師 | |
彼れ | |
魔法 | |
良し | |
魔女 | |
仕方無い | |
此処 | |
貴方 | |
達 | |
糞 | |
有り難う | |
積り | |
此方 | |
良く | |
怪物 | |
彼奴 | |
其奴 | |
師 | |
剣 | |
此奴 | |
野郎 | |
魔術 | |
急度 | |
旨い | |
彼れ | |
侭 | |
狼 | |
衛兵 | |
失せる | |
扠 | |
仕方無い | |
魔女 | |
良し | |
成る程 | |
魔法 | |
矢張り | |
軍団 | |
漸と | |
男爵 | |
御陰 | |
追い追い | |
落ち着ける | |
神々 | |
援護 | |
痕跡 | |
族長 | |
巨人 | |
何者 | |
喋り | |
屋 | |
一族 | |
洞窟 | |
余所者 | |
縦し | |
貴様 | |
我 | |
灘 | |
仕舞い | |
罠 | |
妖婆 | |
立ち去る | |
放つ | |
聖堂 | |
御座る | |
食らう | |
亡霊 | |
公爵 | |
栄光 | |
真 | |
婆 | |
吸血 | |
仇 | |
人殺し | |
団 | |
見捨てる | |
皇帝 | |
鎧 | |
貴 | |
正気 | |
追い払う | |
抑 | |
糞垂れ | |
伯爵 | |
幽鬼 | |
村人 | |
陛下 | |
御輿 | |
我が | |
打ち殺す | |
容赦 | |
試練 | |
加護 | |
樟 | |
仕業 | |
間抜け | |
巻き込む | |
熊 | |
幾 | |
彷徨く | |
茸 | |
見張る | |
部隊 | |
戦士 | |
慈悲 | |
薬草 | |
仮面 | |
手下 | |
光栄 | |
盗賊 | |
祈祷 | |
遺体 | |
丁度 | |
悪党 | |
火炙り | |
霊薬 | |
狩り | |
菜 | |
変異 | |
兵 | |
突き立つ | |
腰抜け | |
寄越す | |
親父 | |
肢 | |
突き込む | |
精霊 | |
駄々 | |
殺し | |
結末 | |
呪文 | |
沼地 | |
常 | |
騎士 | |
水晶 | |
否々 | |
遣る気 | |
止め | |
可笑しな | |
餓鬼 | |
爺 | |
切り落とす | |
王者 | |
裏切り | |
伏せる | |
付き纏う | |
報い | |
殺し屋 | |
回り込む | |
同然 | |
大袈裟 | |
血塗れ | |
閣下 | |
祝福 | |
物乞い | |
拷問 | |
女神 | |
斧 | |
此の世 | |
法螺 | |
復讐 | |
頼り | |
出会す | |
隠れ家 | |
晒す | |
生き延びる | |
増援 | |
流派 | |
諜報 | |
未だ未だ | |
今頃 | |
箇月 | |
皆殺し | |
仕留める | |
降参 | |
放浪 | |
荷馬 | |
納屋 | |
減り | |
埋葬 | |
司祭 | |
果樹 | |
表わす | |
企む | |
引き摺る | |
族 | |
宿屋 | |
隠れん坊 | |
猶 | |
説教 | |
脚 | |
目撃 | |
閉じ込める | |
断り | |
挑発 | |
生き残る | |
其々 | |
邪悪 | |
温かい | |
正体 | |
薔薇 | |
帝国 | |
栗鼠 | |
烏頭 | |
弟子 | |
偵察 | |
馬歯 | |
悪夢 | |
見返り | |
標的 | |
攫う | |
死人 | |
競売 | |
小船 | |
旅人 | |
思い知る | |
疾っく | |
怖じ気 | |
何奴 | |
制圧 | |
御伽話 | |
流れ者 | |
吟遊 | |
闘技 | |
驢馬 | |
羊 | |
聖 | |
色んな | |
起動 | |
見失う | |
放し | |
本題 | |
最 | |
出でる | |
齎す | |
無力 | |
隊長 | |
石弓 | |
山羊 | |
送り込む | |
遣り直す | |
度胸 | |
傭兵 | |
小娘 | |
陸でなし | |
馳走 | |
引き裂く | |
疫病 | |
領主 | |
打ちのめす | |
振り回す | |
保護 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment