From db0682203cff791cb630411b9898888d63b6e911 Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Wed, 22 Apr 2026 22:11:44 -0700 Subject: [PATCH] these two are it --- add-readings.py | 21 +++++++++------------ get-properties.py | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/add-readings.py b/add-readings.py index 7dc3fcb..8369b97 100644 --- a/add-readings.py +++ b/add-readings.py @@ -58,27 +58,24 @@ def annotate_phrase(text: str) -> str: #print(annotate_phrase("私は学校へ行きます")) -with open("words-readings.json", "r", encoding="utf-16le") as f: - readings = json.load(f) - -with open("dump.json", "r", encoding="utf-16le") as f: +with open("dump2.json", "r", encoding="utf-16") as f: dump = json.load(f) vocab_dict = {} ## A micab phrase based word parser for cd in dump: - print(dump[cd]['nm']) - # node = tagger.parseToNode(dump[cd]['nm']) + print(dump[cd]['name_J']) + # node = tagger.parseToNode(dump[cd]['name_J']) # while node: # # node.surface is the word; node.feature contains POS tags # if node.surface: # print(f"{node.surface}\t{node.feature}") # node = node.next - anottated = annotate_phrase(dump[cd]['nm']) - if anottated['reading'] != dump[cd]['nm']: + anottated = annotate_phrase(dump[cd]['name_J']) + if anottated['reading'] != dump[cd]['name_J']: print(anottated['reading']) dump[cd]['kana'] = anottated['reading'] - cd_nm = dump[cd]['nm'] + cd_nm = dump[cd]['name_J'] for word in anottated['vocab']: # Skip punctuation words hopefully if len(word) == 1 and has_kanji(word) == False: @@ -93,11 +90,11 @@ for cd in dump: if cd_nm not in vocab_dict[word]['Examples']: vocab_dict[word]['Examples'] += (cd_nm,) print() - phrase = dump[cd]['de'] + phrase = dump[cd]['desc_J'] anottated = annotate_phrase(phrase) if anottated['reading'] != phrase: #print(anottated['reading']) - dump[cd]['furi_de'] = anottated['reading'] + dump[cd]['desc_Furi'] = anottated['reading'] for word in anottated['vocab']: if len(word) == 1 and has_kanji(word) == False: continue @@ -114,7 +111,7 @@ for cd in dump: vocab_dict = sorted(vocab_dict.items(), key= lambda x: x[1]['count'], reverse=True) -with open("dump-withkana2.json", "w", encoding="utf-16") as outfile: +with open("dump2.json", "w", encoding="utf-16") as outfile: json.dump(dump, outfile, ensure_ascii=False, indent=2) with open("dump-vocab.json", "w", encoding="utf-16") as outfile: diff --git a/get-properties.py b/get-properties.py index 5d5cb25..a145ae1 100644 --- a/get-properties.py +++ b/get-properties.py @@ -1,6 +1,7 @@ import mmap import struct from pathlib import Path +import json prop_data = Path(f"YGO_2020/bin/CARD_Prop.bin").read_bytes() # Get all the bytes @@ -86,7 +87,7 @@ desc_data = Path(f"YGO_2020/bin/CARD_Desc_{language_code}.bin").read_bytes() get_props() -with open("dump2.json", "w", encoding="utf-16le") as outfile: +with open("dump2.json", "w", encoding="utf-16") as outfile: json.dump(cd_db, outfile, ensure_ascii=False, indent=2) print()