Skip to content

Simple Python package (CLI/Python API) for getting japanese readings (yomigana) and accents using MeCab.

License

Notifications You must be signed in to change notification settings

34j/mecab-text-cleaner

Repository files navigation

MeCab Text Cleaner

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

This is a simple Python package for getting japanese readings (yomigana) and accents using MeCab. Please also consider using pyopenjtalk (no accents) or pyopenjtalk_g2p_prosody (ESPnet) (with accents), as this package does not account for accent changes in compound words.

Installation

Install this via pip or pipx (or your favourite package manager):

pipx install mecab-text-cleaner[unidecode,unidic]
pip install mecab-text-cleaner[unidecode,unidic]

Usage

> mtc いい天気ですね。
イ]ー テ]ンキ デス ネ。
> mtc いい天気ですね。 --ascii
i] te]nki desu ne.
> mtc いい天気ですね --no-add-atype --no-add-blank-between-words
イーテンキデスネ
> mtc いい天気ですね --no-add-atype --no-add-blank-between-words -r kana
イイテンキデスネ
from mecab_text_cleaner import to_reading, to_ascii_clean

assert to_reading("     空、雲。\n雨!(") == "ソ]ラ、 ク]モ。\nア]メ!("
assert to_ascii_clean("      한空、雲。\n雨!(") == "han so]ra, ku]mo. \na]me!("

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!