Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chezou/Mykytea-python

Repository files navigation

PyPI version

Mykytea-python is a Python wrapper module for KyTea, a general text analysis toolkit.KyTea is developed by KyTea Development Team.

Detailed information on KyTea can be found at:http://www.phontron.com/kytea

Installation

Install Mykytea-python via pip

You can install Mykytea-python viapip.

pip install kytea

You don't have to install KyTea anymore before installing Mykytea-python when you install it by using wheel on PyPI.

You should have any KyTea model on your machine.

Build Mykytea-python from source

If you want to build from source, you need to install KyTea.

Then, run

make

After make, you can install Mykytea-python by running

make install

If you fail to make, please try to install SWIG and run

swig -c++ -python -I/usr/local/include mykytea.i

Or if you still fail on Max OS X, run with some variables

$ ARCHFLAGS="-arch x86_64" CC=gcc CXX=g++ make

If you compiled kytea with clang, you need ARCHFLAGS only.

Or, you use macOS and Homebrew, you can useKYTEA_DIR to pass the directory of KyTea.

brew install kyteaKYTEA_DIR=$(brew --prefix) make all

How to use it?

Here is the example code to use Mykytea-python.

importMykyteadefshowTags(t):forwordint:out=word.surface+"\t"fort1inword.tag:fort2int1:fort3int2:out=out+"/"+str(t3)out+="\t"out+="\t"print(out)deflist_tags(t):defconvert(t2):return (t2[0],type(t2[1]))return [(word.surface, [[convert(t2)fort2int1]fort1inword.tag])forwordint]# Pass arguments for KyTea as the following:opt="-model /usr/local/share/kytea/model.bin"mk=Mykytea.Mykytea(opt)s="今日はいい天気です。"# Fetch segmented wordsforwordinmk.getWS(s):print(word)# Show analysis resultsprint(mk.getTagsToString(s))# Fetch first best tagt=mk.getTags(s)showTags(t)# Show all tagstt=mk.getAllTags(s)showTags(tt)

License

MIT License


[8]ページ先頭

©2009-2025 Movatter.jp