Skip to main content

A text analysis toolkit KyTea binding

Project description

KyTea wrapper for python

Patreon

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

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

Install Dependencies

You need to install KyTea before build.

To install Mykytea-python, run

pip install kytea

To build Mykytea-python, run (if you don't want to use pip)

make

If you want to install, run

sudo 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 can use brew to install kytea.

brew install kytea
KYTEA_DIR=$(brew --prefix) make all

How to use it?

Here is the example code to use Mykytea-python.

import Mykytea

def showTags(t):
    for word in t:
        out = word.surface + "\t"
        for t1 in word.tag:
            for t2 in t1:
                for t3 in t2:
                    out = out + "/" + str(t3)
                out += "\t"
            out += "\t"
        print(out)

def list_tags(t):
    def convert(t2):
        return (t2[0], type(t2[1]))
    return [(word.surface, [[convert(t2) for t2 in t1] for t1 in word.tag]) for word in t]

# Pass arguments for KyTea as the following:
opt = "-model /usr/local/share/kytea/model.bin"
mk = Mykytea.Mykytea(opt)

s = "今日はいい天気です。"

# Fetch segmented words
for word in mk.getWS(s):
    print(word)

# Show analysis results
print(mk.getTagsToString(s))

# Fetch first best tag
t = mk.getTags(s)
showTags(t)

# Show all tags
tt = mk.getAllTags(s)
showTags(tt)

License

MIT License

Project details


Download files

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

Source Distribution

kytea-0.1.9a1.tar.gz (73.9 kB view hashes)

Uploaded Source

Built Distributions

kytea-0.1.9a1-cp312-cp312-win_amd64.whl (319.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

kytea-0.1.9a1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

kytea-0.1.9a1-cp312-cp312-macosx_11_0_arm64.whl (719.6 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

kytea-0.1.9a1-cp312-cp312-macosx_10_9_x86_64.whl (735.9 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

kytea-0.1.9a1-cp311-cp311-win_amd64.whl (318.4 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

kytea-0.1.9a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

kytea-0.1.9a1-cp311-cp311-macosx_11_0_arm64.whl (718.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

kytea-0.1.9a1-cp311-cp311-macosx_10_9_x86_64.whl (734.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

kytea-0.1.9a1-cp310-cp310-win_amd64.whl (318.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

kytea-0.1.9a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

kytea-0.1.9a1-cp310-cp310-macosx_11_0_arm64.whl (718.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

kytea-0.1.9a1-cp310-cp310-macosx_10_9_x86_64.whl (734.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

kytea-0.1.9a1-cp39-cp39-win_amd64.whl (318.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

kytea-0.1.9a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

kytea-0.1.9a1-cp39-cp39-macosx_11_0_arm64.whl (718.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

kytea-0.1.9a1-cp39-cp39-macosx_10_9_x86_64.whl (734.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

kytea-0.1.9a1-cp38-cp38-win_amd64.whl (318.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

kytea-0.1.9a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

kytea-0.1.9a1-cp38-cp38-macosx_10_9_x86_64.whl (735.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ 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