Skip to content

Instantly share code, notes, and snippets.

@labocho
Created May 21, 2025 05:22
Show Gist options
  • Save labocho/cd9466bb18af9de6d4d1d11a8ecd091c to your computer and use it in GitHub Desktop.
Save labocho/cd9466bb18af9de6d4d1d11a8ecd091c to your computer and use it in GitHub Desktop.
漢字まじりの日本語の読みを推定して出力
# 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