Python wrapper for the MeCab-ko morphological analyzer for Korean
Project description
This is a Python wrapper for the MeCab-ko morphological analyzer for Korean text. It works with Python 3.6 and greater.
There are several implementations of python binding or wrapper for MeCab-ko, but they are generally not well maintained.
I made it to stand on the shoulders of giants(well-maintained open-source projects like MeCab, mecab-ko and mecab-python3) with minimum modifications.
I initially named it mecab-ko-python3
because the package name referenced for development was mecab-python3,
it may seem a little arrogant, but to reduce confusion in the PyPI, the name was changed to 'mecab-ko'.
(The repository is named 'pymecab-ko' to distinguish it from original mecab-ko)
Note: If using MacOS Big Sur, you'll need to upgrade pip to version 20.3 or higher to use wheels due to a pip issue.
issue를 영어로 작성할 필요는 없습니다.
Note that Windows wheels require a Microsoft Visual C++ Redistributable, so be sure to install that.
Basic usage
>>> import mecab_ko as MeCab
>>> tagger = MeCab.Tagger("-Owakati")
>>> tagger.parse("아버지가방에들어가신다").split()
['아버지', '가', '방', '에', '들어가', '신다']
>>> tagger = MeCab.Tagger()
>>> print(tagger.parse("아버지가방에들어가신다"))
아버지 NNG,*,F,아버지,*,*,*,*
가 JKS,*,F,가,*,*,*,*
방 NNG,*,T,방,*,*,*,*
에 JKB,*,F,에,*,*,*,*
들어가 VV,*,F,들어가,*,*,*,*
신다 EP+EC,*,F,신다,Inflect,EP,EC,시/EP/*+ㄴ다/EC/*
EOS
The API for pymecab-ko
closely follows the API for MeCab itself,
even when this makes it not very “Pythonic.” Please consult the official MeCab
documentation for more information.
Installation
Binary wheels are available for MacOS X, Linux, and Windows (64bit) are
installed by default when you use pip
:
pip install mecab-ko
These wheels include an internal (statically linked) copy of the MeCab library,
but not dictionary. In order to use MeCab you'll need to install a dictionary.
mecab-ko-dic
is a good one to start with:
pip install mecab-ko-dic
To build from source using pip,
pip install --no-binary :all: mecab-ko
Dictionaries
There is a unique dictionary available for MeCab-ko. These UniDic packages, which include slight modifications for ease of use, are recommended:
- mecab-ko-dic: The pre-built mecab-ko-dic 2.1.1-20180720 based on ipadic-py.
- mecab-ko-dic: The original source-code of mecab-ko-dic to build dictionary for mecab-ko.
Common Issues
If you get a RuntimeError
when you try to run MeCab, here are some things to check:
Windows Redistributable
You have to install this to use this package on Windows.
Installing a Dictionary
Run pip install mecab-ko-dic
and confirm that works. If that fixes your
problem, you either don't have a dictionary installed, or you need to specify
your dictionary path like this:
tagger = MeCab.Tagger('-r /dev/null -d /usr/local/lib/mecab/dic/mydic')
Note: on Windows, use nul
instead of /dev/null
. Alternately, if you have a
mecabrc
you can use the path after -r
.
Specifying a mecabrc
If you get this error:
error message: [ifs] no such file or directory: /usr/local/etc/mecabrc
You need to specify a mecabrc
file. It's OK to specify an empty file, it just
has to exist. You can specify a mecabrc
with -r
. This may be necessary on
Debian or Ubuntu, where the mecabrc
is in /etc/mecabrc
.
You can specify an empty mecabrc
like this:
tagger = MeCab.Tagger('-r/dev/null -d/home/hoge/mydic')
Using Unsupported Output Modes like -Ochasen
Chasen output is not a built-in feature of MeCab, you must specify it in your
dicrc
or mecabrc
. Notably, mecab-ko-dic does not include Chasen output format.
Please see the MeCab documentation.
Alternatives
- python-mecab-ko is a Python binding for MeCab-ko
- mecab-python-msvc is a mecab-python for mecab-ko-msvc
- KoNLPy is a library for Korean NLP that includes a MeCab wrapper
Licensing
Like MeCab and mecab-python3, pymecab-ko
is copyrighted free software by
Taku Kudo taku@chasen.org and Nippon Telegraph and Telephone Corporation,
and is distributed under a 3-clause BSD license (see the file BSD
).
Alternatively, it may be redistributed under the terms of the
GNU General Public License, version 2 (see the file GPL
) or the
GNU Lesser General Public License, version 2.1 (see the file LGPL
).
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 Distributions
Built Distributions
Hashes for mecab_ko-0.0.1a0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee1990170bfca35bd41cdff74877fbd51b48238f1eee937014973c4d8d39276 |
|
MD5 | 5f2eea67f4d3523c9fe7540b64d51940 |
|
BLAKE2b-256 | 693bc185c43dc261e0ec5915c943e10e3795a1a4ac26f484fdc2667f22a9968e |
Hashes for mecab_ko-0.0.1a0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da7f8d11874365d2b1996f750169c3eee3c216a325ecc53934edc0a0a921057 |
|
MD5 | c53b41704711f588b1758a6293acec66 |
|
BLAKE2b-256 | 78fb6d73803d2f6412afa99019bb1064752d657822d99fc24c3655dc23ee9a55 |
Hashes for mecab_ko-0.0.1a0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7860e9dffa9ee2cd70701f4c55d65a95e82ee4cabbae9efdb41a339844ca2e86 |
|
MD5 | 451ef85028b7c74bec6ceb88764505b5 |
|
BLAKE2b-256 | 3f322b8f01dbeb37704362e877df71f0bf4e1803f0aacfe2b0770082173d95f3 |
Hashes for mecab_ko-0.0.1a0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c44938175ec8bc52dcbc230c4fab548013713bbf7ce9bafce7c62bf2f5ab56b8 |
|
MD5 | 9fa062080a2c056573fc768d62d84639 |
|
BLAKE2b-256 | a5bda05937c39e46a56ec137d2ec3df84cae5c44d156a09d6ca8db775701f7be |
Hashes for mecab_ko-0.0.1a0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f1a183397853dfe156175c9a87be774ef14bf172810254bad0d20ffd0b1e64b |
|
MD5 | cc573f842f6be31e75f4613a63915630 |
|
BLAKE2b-256 | c16ca3e43990a891925aaee5c18f84d57b56194900ad18a8773712c85225a798 |
Hashes for mecab_ko-0.0.1a0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49750853b44d7f2bed2c2e48a5cec4ed8e015c7a6cb3ad94d9a9146971219b0 |
|
MD5 | 9760565ab1b62b39d3457848c3daf6ad |
|
BLAKE2b-256 | 67a9f59560373f77acab40587f53705454907e05d7e8ee32e1e3d8e3d13bcf4c |
Hashes for mecab_ko-0.0.1a0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdbda65b6889b07077764e472ac74620cc9cf7cc94dd9c2ad9ae2f98263e72d6 |
|
MD5 | 90421d35f50e7e35067f265759ebc440 |
|
BLAKE2b-256 | 632b9be8ac90256e865a23a6143ef9ec10621c87c7efa985e1a717398d8a41e5 |
Hashes for mecab_ko-0.0.1a0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd97d0e04b920a062a64a41254588222a615e6efb6bc8c1d34d4805a2961148e |
|
MD5 | 5a6607f6b39457dfc79bb08c48fa0ae5 |
|
BLAKE2b-256 | c307118c2431e84cfa34d7f28f74cc7dda4d2b69daebfd78fb8270357e784a92 |
Hashes for mecab_ko-0.0.1a0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f09855e41ff36796103c0eaee8946ca058973df20949d590043a8aac71115e5b |
|
MD5 | de7168b6c9041d7ba6e7a2bc0baad7ed |
|
BLAKE2b-256 | 98e3d4009083ce9e5301c526d918475af86a265c0fa12360b1d27023fb5d6646 |
Hashes for mecab_ko-0.0.1a0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85fc60d558e5224a4968e18a0545aabe6a3070161f96a45d81d9dd1f2c35f161 |
|
MD5 | 1e9805d4a694ebd10ce2085a8d3caecd |
|
BLAKE2b-256 | dca61c54a76848575145aabb2bf40a9e16f2214ca4df3e192a8a60ae92d00e5a |
Hashes for mecab_ko-0.0.1a0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d0548c2da27a81f9679ceb344056d194f81fc673c9c203878608b40138e7f19 |
|
MD5 | b331c89dee542ad5393d2f9bfe1141c7 |
|
BLAKE2b-256 | 9d1be1dc277cc5cef0a04beb4ef4943ddc601cdf217163eb107c2481a9eb3142 |
Hashes for mecab_ko-0.0.1a0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f6186adbf5374d451ce36b4435c2052f3127f5dbc2803f89b5d5cfec9febc0 |
|
MD5 | d793a45b2a70399fc8dad38e2b4aae58 |
|
BLAKE2b-256 | 0eb1a6d6672a4154e133281727d88051c960c094c3919a2d5e78d53cf2cf27cf |