Skip to main content

SudachiPy

PyPi version Build Status

日本語

SudachiPy is a Python version of Sudachi, a Japanese morphological analyzer.

TL;DR

$ pip install sudachipy sudachidict_core

$ echo "高輪ゲートウェイ駅" | sudachipy
高輪ゲートウェイ駅	名詞,固有名詞,一般,*,*,*	高輪ゲートウェイ駅
EOS

$ echo "高輪ゲートウェイ駅" | sudachipy -m A
高輪	名詞,固有名詞,地名,一般,*,*	高輪
ゲートウェイ	名詞,普通名詞,一般,*,*,*	ゲートウェー
駅	名詞,普通名詞,一般,*,*,*	駅
EOS

$ echo "空缶空罐空きカン" | sudachipy -a
空缶	名詞,普通名詞,一般,*,*,*	空き缶	空缶	アキカン	0
空罐	名詞,普通名詞,一般,*,*,*	空き缶	空罐	アキカン	0
空きカン	名詞,普通名詞,一般,*,*,*	空き缶	空きカン	アキカン	0
EOS

Setup

You need SudachiPy and a dictionary.

Step 1. Install SudachiPy

$ pip install sudachipy

Step 2. Get a Dictionary

You can get dictionary as a Python package. It make take a while to download the dictionary file (around 70MB for the core edition).

$ pip install sudachidict_core

Alternatively, you can choose other dictionary editions. See this section for the detail.

Usage: As a command

There is a CLI command sudachipy.

$ echo "外国人参政権" | sudachipy
外国人参政権	名詞,普通名詞,一般,*,*,*	外国人参政権
EOS
$ echo "外国人参政権" | sudachipy -m A
外国	名詞,普通名詞,一般,*,*,*	外国
人	接尾辞,名詞的,一般,*,*,*	人
参政	名詞,普通名詞,一般,*,*,*	参政
権	接尾辞,名詞的,一般,*,*,*	権
EOS
$ sudachipy tokenize -h
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-a] [-d] [-v]
                          [file [file ...]]

Tokenize Text

positional arguments:
  file           text written in utf-8

optional arguments:
  -h, --help     show this help message and exit
  -r file        the setting file in JSON format
  -m {A,B,C}     the mode of splitting
  -o file        the output file
  -a             print all of the fields
  -d             print the debug information
  -v, --version  print sudachipy version

Output

Columns are tab separated.

  • Surface
  • Part-of-Speech Tags (comma separated)
  • Normalized Form

When you add the -a option, it additionally outputs

  • Dictionary Form
  • Reading Form
  • Dictionary ID
    • 0 for the system dictionary
    • 1 and above for the user dictionaries
    • -1\t(OOV) if a word is Out-of-Vocabulary (not in the dictionary)
$ echo "外国人参政権" | sudachipy -a
外国人参政権	名詞,普通名詞,一般,*,*,*	外国人参政権	外国人参政権	ガイコクジンサンセイケン	0
EOS
echo "阿quei" | sudachipy -a
阿	名詞,普通名詞,一般,*,*,*	阿	阿		-1	(OOV)
quei	名詞,普通名詞,一般,*,*,*	quei	quei		-1	(OOV)
EOS

Usage: As a Python package

Here is an example;

from sudachipy import tokenizer
from sudachipy import dictionary

tokenizer_obj = dictionary.Dictionary().create()
# Multi-granular Tokenization

mode = tokenizer.Tokenizer.SplitMode.C
[m.surface() for m in tokenizer_obj.tokenize("国家公務員", mode)]
# => ['国家公務員']

mode = tokenizer.Tokenizer.SplitMode.B
[m.surface() for m in tokenizer_obj.tokenize("国家公務員", mode)]
# => ['国家', '公務員']

mode = tokenizer.Tokenizer.SplitMode.A
[m.surface() for m in tokenizer_obj.tokenize("国家公務員", mode)]
# => ['国家', '公務', '員']
# Morpheme information

m = tokenizer_obj.tokenize("食べ", mode)[0]

m.surface() # => '食べ'
m.dictionary_form() # => '食べる'
m.reading_form() # => 'タベ'
m.part_of_speech() # => ['動詞', '一般', '*', '*', '下一段-バ行', '連用形-一般']
# Normalization

tokenizer_obj.tokenize("附属", mode)[0].normalized_form()
# => '付属'
tokenizer_obj.tokenize("SUMMER", mode)[0].normalized_form()
# => 'サマー'
tokenizer_obj.tokenize("シュミレーション", mode)[0].normalized_form()
# => 'シミュレーション'

(With 20200330 core dictionary. The results may change when you use other versions)

Dictionary Edition

There are three editions of Sudachi Dictionary, namely, small, core, and full. See WorksApplications/SudachiDict for the detail.

SudachiPy uses sudachidict_core by default. You can specify the dictionary with the link -t command.

$ pip install sudachidict_small
$ sudachipy link -t small
$ pip install sudachidict_full
$ sudachipy link -t full

You can remove the dictionary link with the link -u commnad.

$ sudachipy link -u

Dictionaries are installed as Python packages sudachidict_small, sudachidict_core, and sudachidict_full. SudachiPy tries to refer sudachidict package to use a dictionary. The link subcommand creates a symbolic link of sudachidict_* as sudachidict, to switch the packages.

The dictionary files are not in the package itself, but it is downloaded upon installation.

Dictionary in The Setting File

Alternatively, if the dictionary file is specified in the setting file, sudachi.json, SudachiPy will use that file.

{
    "systemDict" : "relative/path/to/system.dic",
    ...
}

The default setting file is sudachipy/resources/sudachi.json. You can specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

User Dictionary

To use a user dictionary, user.dic, place sudachi.json to anywhere you like, and add userDict value with the relative path from sudachi.json to your user.dic.

{
    "userDict" : ["relative/path/to/user.dic"],
    ...
}

Then specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

You can build a user dictionary with the subcommand ubuild.

WARNING: v0.3.* ubuild contains bug.

$ sudachipy ubuild -h
usage: sudachipy ubuild [-h] [-d string] [-o file] [-s file] file [file ...]

Build User Dictionary

positional arguments:
  file        source files with CSV format (one or more)

optional arguments:
  -h, --help  show this help message and exit
  -d string   description comment to be embedded on dictionary
  -o file     output file (default: user.dic)
  -s file     system dictionary (default: linked system_dic, see link -h)

About the dictionary file format, please refer to this document (written in Japanese, English version is not available yet).

Customized System Dictionary

$ sudachipy build -h
usage: sudachipy build [-h] [-o file] [-d string] -m file file [file ...]

Build Sudachi Dictionary

positional arguments:
  file        source files with CSV format (one of more)

optional arguments:
  -h, --help  show this help message and exit
  -o file     output file (default: system.dic)
  -d string   description comment to be embedded on dictionary

required named arguments:
  -m file     connection matrix file with MeCab's matrix.def format

To use your customized system.dic, place sudachi.json to anywhere you like, and overwrite systemDict value with the relative path from sudachi.json to your system.dic.

{
    "systemDict" : "relative/path/to/system.dic",
    ...
}

Then specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

For Developers

Cython Build

$ python setup.py build_ext --inplace

Code Format

Run scripts/format.sh to check if your code is formatted correctly.

You need packages flake8 flake8-import-order flake8-buitins (See requirements.txt).

Test

Run scripts/test.sh to run the tests.

Contact

Sudachi and SudachiPy are developed by WAP Tokushima Laboratory of AI and NLP.

Open an issue, or come to our Slack workspace for questions and discussion.

https://sudachi-dev.slack.com/ (Get invitation here)

Enjoy tokenization!

Metadata

Release files for SudachiPy 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SudachiPy 0.5.1
File Size Uploaded Provenance Actions
SudachiPy-0.5.1.tar.gz 69.2 kB Without provenance Details for SudachiPy-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for SudachiPy 0.5.1
File Actions
SudachiPy-0.5.1-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for SudachiPy-0.5.1-cp38-cp38-win_amd64.whl
SudachiPy-0.5.1-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details for SudachiPy-0.5.1-cp38-cp38-win32.whl
SudachiPy-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.14+ x86-64 Details for SudachiPy-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl
SudachiPy-0.5.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for SudachiPy-0.5.1-cp37-cp37m-win_amd64.whl
SudachiPy-0.5.1-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details for SudachiPy-0.5.1-cp37-cp37m-win32.whl
SudachiPy-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64 Details for SudachiPy-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl
SudachiPy-0.5.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for SudachiPy-0.5.1-cp36-cp36m-win_amd64.whl
SudachiPy-0.5.1-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for SudachiPy-0.5.1-cp36-cp36m-win32.whl
SudachiPy-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 Details for SudachiPy-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl

Total release size: 2.4 MB

Release files / SudachiPy-0.5.1.tar.gz

Download URL SudachiPy-0.5.1.tar.gz
Size 69.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c8331883aaac7056f359ce291c07f2b5178279d68891c822c6c8a0f2fc89502c
BLAKE2b-256 checksum
How to use checksums
b72c4401e7573b2c37a34ab45c1e416cfecbf97b7a6101f691babcf9c40a4592
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

Release files / SudachiPy-0.5.1-cp38-cp38-win_amd64.whl

Download URL SudachiPy-0.5.1-cp38-cp38-win_amd64.whl
Size 264.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
c1956c2736b3b65696c4fe6a0e5e4c6c47abc639abac73861174b2e0c91bf85f
BLAKE2b-256 checksum
How to use checksums
4e39095351ea8d57c8721be6b8c7bb0d5b014559d78151777ef1163cc46404cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

Release files / SudachiPy-0.5.1-cp38-cp38-win32.whl

Download URL SudachiPy-0.5.1-cp38-cp38-win32.whl
Size 230.7 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
5e6fcd50aac13f54ed2db0ce5d36f3335b237f325662b13d4ab9f9e0836a1bd6
BLAKE2b-256 checksum
How to use checksums
2f33e976cb8bf613f094981080bf007d2f28c4b5aa352eabb5913cdf96308fd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

Release files / SudachiPy-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl

Download URL SudachiPy-0.5.1-cp38-cp38-macosx_10_14_x86_64.whl
Size 273.9 kB
Tags CPython 3.8 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
b275c820fe04707e0843a05cdddffbd3750f1082d583a6fd5ddbd0360945c486
BLAKE2b-256 checksum
How to use checksums
5494dabc970cde3f9b1f8ac44425075bf8725995801cd6126af3957bc5bc1939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

Release files / SudachiPy-0.5.1-cp37-cp37m-win_amd64.whl

Download URL SudachiPy-0.5.1-cp37-cp37m-win_amd64.whl
Size 259.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
386a32660a34750ca4f9598726d5c287e457ded3c76678d9665570db9f3dda64
BLAKE2b-256 checksum
How to use checksums
2e7bf7bf9b8f74569c498766fad5c5d581490a828b00259fad79af5383bbfbd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

Release files / SudachiPy-0.5.1-cp37-cp37m-win32.whl

Download URL SudachiPy-0.5.1-cp37-cp37m-win32.whl
Size 226.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
2bd7dca95d229e84ab57a7a57252a437a346672e1049efb3ec2621db747a85d8
BLAKE2b-256 checksum
How to use checksums
d2f5f8d5e103ccfa1a536b9f2b25a0559775ff23a95f4b788d7665d19f45fce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

Release files / SudachiPy-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl

Download URL SudachiPy-0.5.1-cp37-cp37m-macosx_10_14_x86_64.whl
Size 273.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
4d9ad6b7938b7b9fb0bef41f85d0c6fd8f3ae2ec9fc2057016f1e20092dc3433
BLAKE2b-256 checksum
How to use checksums
bd23f5cb36732d447aae18dfca8e7c55deb4f3b4989c38d9a5fe5e1be8ba7cc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

Release files / SudachiPy-0.5.1-cp36-cp36m-win_amd64.whl

Download URL SudachiPy-0.5.1-cp36-cp36m-win_amd64.whl
Size 277.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
4e9dbdfd679af1c88c70865014a0dd6c59ac01226db35fca8cf9d5352653781c
BLAKE2b-256 checksum
How to use checksums
0160ab242eb0c1a21a014381ea92be1a2e66d12dd49fda3d10b94065d9239e53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.8

Release files / SudachiPy-0.5.1-cp36-cp36m-win32.whl

Download URL SudachiPy-0.5.1-cp36-cp36m-win32.whl
Size 240.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
63c0dec3cdf174f2e607df8cb177c9e44513e1b13488db31f0ea5a0df9307726
BLAKE2b-256 checksum
How to use checksums
1b26d96c998ed527a9af178569e9cf509c76766d072b013be83af1409c3eadcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.8

Release files / SudachiPy-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl

Download URL SudachiPy-0.5.1-cp36-cp36m-macosx_10_14_x86_64.whl
Size 291.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
a4dbd3e12c157713fee76a3cc137ab07b968b88cafc88d04d090ce590d6dae04
BLAKE2b-256 checksum
How to use checksums
bcdac9c1280dbf37ac1a54100a5cdd72aec66960aba029114066d796703dfe58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.12

Security for SudachiPy 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.1 This release

10 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page