34 lines
826 B
Python
34 lines
826 B
Python
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()
|