commit 138c1467a43856c285746c3a1d62a6365c228b7b Author: Nitsud Yarg Date: Tue Apr 21 19:14:01 2026 -0700 finally set up a repo diff --git a/add-readings.py b/add-readings.py new file mode 100644 index 0000000..8c24f1f --- /dev/null +++ b/add-readings.py @@ -0,0 +1,51 @@ +import json + +# Generate Hiragana and Katakana characters +hiragana = tuple(chr(i) for i in range(12353, 12436)) # \u3041 - \u3094 +katakana = tuple(chr(i) for i in range(12450, 12532)) # \u30A2 - \u30F4 +punctuation = tuple(chr(i) for i in range(65281, 65382)) + +# Combine both into one tuple +all_kana = hiragana + katakana + punctuation + (' ', 'ー', '・') + + +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: + dump = json.load(f) + +## Iterates through all the keys not values +for cd in dump: + word = '' + new_name = '' + for char in dump[cd]['nm'] + '・': ## hacky char add to prevent dupe logic + if char in all_kana: + if len(word) > 0: + #print(word) + if readings.get(word) is not None: + kana = None + try: + #print("<--", readings[word]['kana']) + kana = readings[word]['kana'] + new_name += '(' + kana + ')' + #print() + except TypeError as e: + kana = None + #words[word] = (words[word] + 1) + else: + print(word, " <- Not Found") + word = '' + else: + word += char + new_name += char + if new_name[:-1]!= dump[cd]['nm']: + print (dump[cd]['nm']) + print (new_name[:-1]) + dump[cd]['kana'] = new_name[:-1] + ## Might need catch for end of string still + +print() + +with open("dump-withkana.json", "w", encoding="utf-16le") as outfile: + json.dump(dump, outfile, ensure_ascii=False, indent=2) diff --git a/extract_cards.py b/extract_cards.py new file mode 100644 index 0000000..d48d185 --- /dev/null +++ b/extract_cards.py @@ -0,0 +1,156 @@ +import mmap +import struct +import json +from pathlib import Path + +# Generate Hiragana and Katakana characters +hiragana = tuple(chr(i) for i in range(12353, 12436)) # \u3041 - \u3094 +katakana = tuple(chr(i) for i in range(12450, 12532)) # \u30A2 - \u30F4 + +# Combine both into one tuple +all_kana = hiragana + katakana + +# Print example +print(all_kana) + +prop_data = Path(f"YGO_2020/bin/CARD_Prop.bin").read_bytes() # Get all the bytes + +language_code = 'J' +offsets_data = Path(f"YGO_2020/bin/CARD_Indx_{language_code}.bin").read_bytes() # Get all the bytes +name_data = Path(f"YGO_2020/bin/CARD_Name_{language_code}.bin").read_bytes() # Get all the bytes +desc_data = Path(f"YGO_2020/bin/CARD_Desc_{language_code}.bin").read_bytes() +offsets = [x[0] for x in struct.iter_unpack(" 0: + if words.get(word) is None: + words[word] = 0 + print(word) + words[word] = (words[word] + 1) + word = '' + else: + word += char + if len(word) > 0: + if words.get(word) is None: + words[word] = 0 + print(word) + words[word] = (words[word] + 1) + + + + end = desc_start_off + while end + 1 < len(desc_data): + ## Read 2 bytes at a time until null found + if desc_data[end:end+2] == b"\x00\x00": + break + end += 2 + desc = desc_data[desc_start_off:end].decode("utf-16le", errors="replace") + + + #print(name) + cd_db[cd_db_ctr] = {"nm":name, "de": desc, "nm_addr":hex(name_start_off), "de_addr":hex(desc_start_off)} + cd_db_ctr += 1 + #print() + ## Iterate offset + off += 2 + +language_code = 'E' +offsets_data = Path(f"YGO_2020/bin/CARD_Indx_{language_code}.bin").read_bytes() # Get all the bytes +name_data = Path(f"YGO_2020/bin/CARD_Name_{language_code}.bin").read_bytes() # Get all the bytes +desc_data = Path(f"YGO_2020/bin/CARD_Desc_{language_code}.bin").read_bytes() +offsets = [x[0] for x in struct.iter_unpack("> 14) & 511) * 10 + card_defense = ((card_bytes >> 18) & 511) * 10 + + print(card_id , card_attack, card_attack, 'idx', card_index_name_data, card_index_desc_data) + #read until null found + end = card_index_name_data + while end + 1 < len(name_data): + ## Read 2 bytes at a time until null found + if name_data[end:end+2] == b"\x00\x00": + break + end += 2 + name = name_data[card_index_name_data:end].decode("utf-16le", errors="replace") + print(name) + #print(card_id.hex(' ')) + # 2. Get last 14 bits using mask 0x3FFF (binary 11 1111 1111 1111) + #print([bin(x) for x in card_first]) + test += 1 + # if test > 3: + # break; + #print(prop_data[r:r+8]) + + diff --git a/get_readings.py b/get_readings.py new file mode 100644 index 0000000..bc42dbc --- /dev/null +++ b/get_readings.py @@ -0,0 +1,33 @@ +import json +from janome.tokenizer import Tokenizer +from kotobase import Kotobase + +kb = Kotobase() +tokenizer = Tokenizer() + +parts = [] +for token in tokenizer.tokenize('魔草トークン'): + print(token) + print(token.reading) + reading = token.reading + if reading == "*": + reading = token.surface + parts.append(reading) + +print(parts) + +with open("words.json", "r", encoding="utf-16le") as f: + words = json.load(f) + +for word in words: + result = kb.lookup(word) + if result: + if len(result.entries) > 0: + kana = result.entries[0].kana[0] + print (result.word, ": ", kana) + words[word] = {"kana":kana,"count":words[word]} + +with open("words-readings.json", "w", encoding="utf-16le") as outfile: + json.dump(words, outfile, ensure_ascii=False, indent=2) + +print() diff --git a/get_readings2.py b/get_readings2.py new file mode 100644 index 0000000..5288e69 --- /dev/null +++ b/get_readings2.py @@ -0,0 +1,67 @@ +import json +from janome.tokenizer import Tokenizer +from kotobase import Kotobase + +kb = Kotobase() +tokenizer = Tokenizer() + +with open("words.json", "r", encoding="utf-16le") as f: + words = json.load(f) + +# Generate Hiragana and Katakana characters +hiragana = tuple(chr(i) for i in range(12353, 12436)) # \u3041 - \u3094 +katakana = tuple(chr(i) for i in range(12450, 12532)) # \u30A2 - \u30F4 +punctuation = tuple(chr(i) for i in range(65281, 65382)) + +# Combine both into one tuple +all_kana = hiragana + katakana + punctuation + (' ', 'ー', '・') + + +with open("dump.json", "r", encoding="utf-16le") as f: + dump = json.load(f) + +readings = {} +## Iterates through all the keys not values +for cd in dump: + word = '' + for char in dump[cd]['nm'] + '・': ## hacky char add to prevent dupe logic + if char in all_kana: + if len(word) > 0: + #print(word) + if readings.get(word) is None: + kana = None + try: + result = kb.lookup(word) + if result: + if len(result.entries) > 0: + kana = result.entries[0].kana[0] + print (result.word, ": ", kana) + readings[word] = {"kana":kana} + else: + print("no entries") + for k in result.kanji: + if len(k.kunyomi) > 0: + print(k.kunyomi[0]) + except TypeError as e: + kana = None + #words[word] = (words[word] + 1) + word = '' + else: + word += char + ## Might need catch for end of string still + + +print() + +# for word in words: +# result = kb.lookup(word) +# if result: +# if len(result.entries) > 0: +# kana = result.entries[0].kana[0] +# print (result.word, ": ", kana) +# words[word] = {"kana":kana,"count":words[word]} + +with open("words-readings.json", "w", encoding="utf-16le") as outfile: + json.dump(readings, outfile, ensure_ascii=False, indent=2) + +print() diff --git a/kana_assc.py b/kana_assc.py new file mode 100644 index 0000000..43929e3 --- /dev/null +++ b/kana_assc.py @@ -0,0 +1,27 @@ + +import mmap +import struct +from pathlib import Path + + +kana1_data = Path("YGO_2020/CARD_Kana1_J.bin").read_bytes() +kana2_data = Path("YGO_2020/CARD_Kana2_J.bin").read_bytes() +kana3_data = Path("YGO_2020/CARD_Kana3_J.bin").read_bytes() + +## The offsets pulled from the file +items1 = [x[0] for x in struct.iter_unpack("