52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
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)
|