Skip to main content

A Cython wrapper for MeCab

Project description

Current PyPI packages

fugashi

Fugashi by Irasutoya

Fugashi is a Cython wrapper for MeCab, a Japanese tokenizer and morphological analysis tool. Wheels are provided for Linux, OSX, and Win64, and UniDic is easy to install (see docs below).

See the blog post for background on why Fugashi exists and some of the design decisions.

If you are on an unsupported platform (like PowerPC), you'll need to install MeCab first. It's recommended you install from source.

Usage

from fugashi import Tagger

tagger = Tagger('-Owakati')
text = "麩菓子(ふがし)は、麩を主材料とした日本の菓子。"
tagger.parse(text)
# => '麩 菓子 ( ふ が し ) は 、 麩 を 主材 料 と し た 日本 の 菓子 。'
for word in tagger(text):
    print(word, word.feature.lemma, word.pos, sep='\t')
    # "feature" is the Unidic feature data as a named tuple

Installing a Dictionary

Fugashi requires a dictionary. UniDic is recommended, and two easy-to-install versions are provided.

  • unidic-lite, a 2013 version of Unidic that's relatively small
  • unidic, the latest UniDic 2.3.0, which is 1GB on disk and requires a separate download step

If you just want to make sure things work you can start with unidic-lite, but for more serious processing unidic is recommended. For production use you'll generally want to generate your own dictionary too; for details see the MeCab documentation.

To get either of these dictionaries, you can install them directly using pip or do the below:

pip install fugashi[unidic-lite]

# The full version of UniDic requires a separate download step
pip install fugashi[unidic]
python -m unidic download

Dictionary Use

Fugashi is written with the assumption you'll use Unidic to process Japanese, but it supports arbitrary dictionaries.

If you're using a dictionary besides Unidic you can use the GenericTagger like this:

from fugashi import GenericTagger
tagger = GenericTagger()

# parse can be used as normal
tagger.parse('something')
# features from the dictionary can be accessed by field numbers
for word in tagger(text):
    print(word.surface, word.feature[0])

You can also create a dictionary wrapper to get feature information as a named tuple.

from fugashi import GenericTagger, create_feature_wrapper
CustomFeatures = create_feature_wrapper('CustomFeatures', 'alpha beta gamma')
tagger = GenericTagger(wrapper=CustomFeatures)
for word in tagger.parseToNodeList(text):
    print(word.surface, word.feature.alpha)

Alternatives

If you have a problem with Fugashi feel free to open an issue. However, there are some cases where it might be better to use a different library.

  • If you want to use MeCab on a platform we don't have wheels for, but don't have a C compiler, use natto-py.
  • If you don't want to deal with installing MeCab at all, try SudachiPy.
  • If you need to work with Korean, try KoNLPy.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fugashi-0.2.2.tar.gz (333.2 kB view hashes)

Uploaded Source

Built Distributions

fugashi-0.2.2-cp38-cp38-win_amd64.whl (497.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

fugashi-0.2.2-cp38-cp38-manylinux1_x86_64.whl (478.6 kB view hashes)

Uploaded CPython 3.8

fugashi-0.2.2-cp38-cp38-macosx_10_14_x86_64.whl (42.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

fugashi-0.2.2-cp37-cp37m-win_amd64.whl (496.0 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

fugashi-0.2.2-cp37-cp37m-manylinux1_x86_64.whl (466.1 kB view hashes)

Uploaded CPython 3.7m

fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl (42.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

fugashi-0.2.2-cp36-cp36m-win_amd64.whl (496.0 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

fugashi-0.2.2-cp36-cp36m-manylinux1_x86_64.whl (465.8 kB view hashes)

Uploaded CPython 3.6m

fugashi-0.2.2-cp36-cp36m-macosx_10_14_x86_64.whl (43.2 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

fugashi-0.2.2-cp35-cp35m-win_amd64.whl (494.8 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

fugashi-0.2.2-cp35-cp35m-manylinux1_x86_64.whl (462.0 kB view hashes)

Uploaded CPython 3.5m

fugashi-0.2.2-cp35-cp35m-macosx_10_14_x86_64.whl (41.2 kB view hashes)

Uploaded CPython 3.5m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page