def main(args): col = ankipandas.Collection() cards = col.cards.merge_notes() reading_cards = cards[cards["cdeck"] == "1a_myChinese\x1fReading"] currently_learning_cards = reading_cards[ (reading_cards["cqueue"] == "learning") | (reading_cards["cqueue"] == "in learning")] trad_chars = currently_learning_cards.apply(lambda row: row["nflds"][1], axis=1).tolist() learning_sentences = [] sentence_df = pd.read_csv("data/graded_sentences.csv") sentence_df["char_list"] = sentence_df.apply( lambda row: list(jieba.cut(row["hanzi"])), axis=1) for char in trad_chars: tmp = sentence_df[pd.DataFrame(sentence_df.char_list.tolist()).isin( [char]).any(1).values] tmp = tmp[:3] for index, row in tmp.iterrows(): learning_sentences.append(row["hanzi"]) random.shuffle(learning_sentences) with open( f"../../Dropbox/chinese_sentences/learning_sentences_{datetime.date.today().strftime('%Y_%m_%d')}__{datetime.datetime.now().time().strftime('%H_%M_%S')}.txt", "w") as ff: for sen in learning_sentences: trad_sen = hanziconv.HanziConv.toTraditional(sen) ff.write(trad_sen + "\n")
def main(args): col = ankipandas.Collection() # note = col.notes["nflds"][501] # selection = col.notes["nflds"][501] selection = col.notes[col.notes['nmodel'] == "Simple Model linedict"] selection["nflds"] = selection.apply(lambda row: row["nflds"], axis=1) # note[-1]="test" # print(note[-1]) # col.notes.update(note) col.notes.update(selection) col.summarize_changes()
def run_example(self, path: Path, save=True): self.log.info("Running example %s", path) col = ankipandas.Collection(self.col_path) # noqa F841 with path.open("r") as example_file: exec(example_file.read()) if save: out = self.output_dir.resolve() / (path.resolve().stem + ".png") self.log.info("Plotting to %s", out) plt.savefig(out, bbox_inches="tight", transparent=True, dpi=75) plt.cla() plt.clf() plt.close()
def save_anki(by_char): col = ankipandas.Collection() han = col.notes[col.notes.nmodel == "Hanzi Writing"].copy() han.fields_as_columns(inplace=True) chars = list(han.nfld_Hanzi) examples = [to_html(char, extract(by_char, char)) for char in chars] print() print("\n".join(examples[:10])) print() han["nfld_Examples"] = examples han.fields_as_list(inplace=True) col.notes.update(han) print(col.summarize_changes()) if click.confirm("Do you want to save? CAREFUL"): print("SAVING...") col.write(modify=True) print("SAVED.")
def colorize_char(char, tone): col = COLS[tone] return f'<span style="color:#{col}">{char}</span>' def colorize_word(word): pinyin_syllabels = pinyin(word, style=Style.TONE3, heteronym=False) tones = [syl[0][-1] for syl in pinyin_syllabels] tones = [tone if tone.isdigit() else "5" for tone in tones] #print(word, tones) return "".join( colorize_char(char, tone) for char, tone in zip(word, tones)) col = ankipandas.Collection() han = col.notes[col.notes.nmodel == "Hanzi Writing"].copy() han.fields_as_columns(inplace=True) chars = list(han.nfld_Hanzi) chars_in_col = set(chars) words = collections.defaultdict(list) for word, rank in sorted(freq.items(), key=lambda x: x[1]): print(word, rank) for char in word: if char in chars_in_col and len(words[char]) < max_words: try:
if koohii_data: with open(resource_path("DATA/kanji_koohii.json"),"ab+") as f: f.write(json.dumps(koohii_data, ensure_ascii=False, indent=4).encode("utf-8")) return koohii_data if __name__ == "__main__": anki_filename, notes_filename = resource_path("DATA/Anki Remembering the Kanji.txt"), resource_path("DATA/Notes Anki Remembering the Kanji.txt") anki_json = resource_path("DATA/deck.json") anki_col_path = resource_path("DATA/Remembering the Kanji.apkg") pd.set_option('display.max_colwidth', None) col = ankipandas.Collection()#"C:\Users\dimit\AppData\Roaming\Anki2\User 1\collection.anki2") print(col.cards.fields_as_columns(inplace=True)) with open(anki_json, "r", encoding="utf-8") as f: """ for i, l in enumerate(f.readlines()[1:]): #print(l.strip()) #if i == 0: break #pattern = ".*Details Story Dictionary (\D)(.*)My Story (.*)Koohii(.*#\d).*(Primitives.*)(Kunyomi:.*)(Onyomi:.*)(Lesson:.*)(JH JLPT Level:.*)(Compounds:.*?)" pattern = ".*Details Story Dictionary (\D)(.*)My Story (.*)Koohii(.*#\d).*(Primitives.*)(Kunyomi:.*)(Onyomi:.*)(Lesson:.*)(JH JLPT Level:.*)(Compounds:.*)" if i == 1: #print(l) regex = re.compile(pattern) #print("\n\n",re.findall(regex, l)) break """