Created
May 21, 2025 05:22
-
-
Save labocho/cd9466bb18af9de6d4d1d11a8ecd091c to your computer and use it in GitHub Desktop.
漢字まじりの日本語の読みを推定して出力
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kanafy.py | |
# pip install 'fugashi[unidic-lite]' jaconv | |
import sys | |
import fugashi | |
import jaconv | |
tagger = fugashi.Tagger() | |
for line in sys.stdin: | |
line = line.strip() | |
if not line: | |
continue | |
result = [] | |
for word in tagger(line): | |
kana = word.feature.kana or word.surface | |
hira = jaconv.kata2hira(kana) | |
result.append(hira) | |
print(''.join(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment