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] [-s string]
                          [-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
  -s string      sudachidict type
  -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

**WARNING: sudachipy link is no longer available in SudachiPy v0.5.2 and later. **

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

SudachiPy uses sudachidict_core by default.

Dictionaries are installed as Python packages sudachidict_small, sudachidict_core, and sudachidict_full.

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

Dictionary option: command line

You can specify the dictionary with the tokenize option -s.

$ pip install sudachidict_small
$ echo "外国人参政権" | sudachipy -s small
$ pip install sudachidict_full
$ echo "外国人参政権" | sudachipy -s full

Dictionary option: Python package

You can specify the dictionary with the Dicionary() argument; config_path or dict_type.

class Dictionary(config_path=None, resource_dir=None, dict_type=None)
  1. config_path
    • You can specify the file path to the setting file with config_path (See [Dictionary in The Setting File](#Dictionary in The Setting File) for the detail).
    • If the dictionary file is specified in the setting file as systemDict, SudachiPy will use the dictionary.
  2. dict_type
    • You can also specify the dictionary type with dict_type.
    • The available arguments are small, core, or full.
    • If different dictionaries are specified with config_path and dict_type, a dictionary defined dict_type overrides those defined in the config path.
from sudachipy import tokenizer
from sudachipy import dictionary

# default: sudachidict_core
tokenizer_obj = dictionary.Dictionary().create()  

# The dictionary given by the `systemDict` key in the config file (/path/to/sudachi.json) will be used
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json").create()  

# The dictionary specified by `dict_type` will be set.
tokenizer_obj = dictionary.Dictionary(dict_type="core").create()  # sudachidict_core (same as default)
tokenizer_obj = dictionary.Dictionary(dict_type="small").create()  # sudachidict_small
tokenizer_obj = dictionary.Dictionary(dict_type="full").create()  # sudachidict_full

# The dictionary specified by `dict_type` overrides those defined in the config path.
# In the following code, `sudachidict_full` will be used regardless of a dictionary defined in the config file. 
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json", dict_type="full").create()  

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 path (default: system core dictionary path)

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.2

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.2
File Size Uploaded Provenance Actions
SudachiPy-0.5.2.tar.gz 70.9 kB Without provenance Details for SudachiPy-0.5.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for SudachiPy 0.5.2
File Actions
SudachiPy-0.5.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for SudachiPy-0.5.2-cp38-cp38-win_amd64.whl
SudachiPy-0.5.2-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details for SudachiPy-0.5.2-cp38-cp38-win32.whl
SudachiPy-0.5.2-cp38-cp38-macosx_10_14_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.14+ x86-64 Details for SudachiPy-0.5.2-cp38-cp38-macosx_10_14_x86_64.whl
SudachiPy-0.5.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for SudachiPy-0.5.2-cp37-cp37m-win_amd64.whl
SudachiPy-0.5.2-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details for SudachiPy-0.5.2-cp37-cp37m-win32.whl
SudachiPy-0.5.2-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.2-cp37-cp37m-macosx_10_14_x86_64.whl
SudachiPy-0.5.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for SudachiPy-0.5.2-cp36-cp36m-win_amd64.whl
SudachiPy-0.5.2-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for SudachiPy-0.5.2-cp36-cp36m-win32.whl
SudachiPy-0.5.2-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.2-cp36-cp36m-macosx_10_14_x86_64.whl

Total release size: 2.4 MB

Release files / SudachiPy-0.5.2.tar.gz

Download URL SudachiPy-0.5.2.tar.gz
Size 70.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e2714bb0958dae3550530ea14b6c1647192203db16aa935c71750f28904b9acf
BLAKE2b-256 checksum
How to use checksums
86c91ccdbb8cb70925b6a6b0b99c2574b453c1dfee08695dd1ebbe6f966bc42f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

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

Download URL SudachiPy-0.5.2-cp38-cp38-win_amd64.whl
Size 264.3 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
39218168593fad019795d75350efd914e81a532babbc153dd5fc044ae9dc0d3e
BLAKE2b-256 checksum
How to use checksums
6515d8a414fa81a09a88a7ef451696bf9e680194dfaef87a2c17eaa5bf7cb24c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

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

Download URL SudachiPy-0.5.2-cp38-cp38-win32.whl
Size 231.0 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
88ac73d76afff772473a5fa863e1ed31a50a2060890b6dc8fadf047c236c3a39
BLAKE2b-256 checksum
How to use checksums
bab41def7b7eeaca2dfd9c29d0b94063f297e2990fb8c135230b4ff44e74923e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

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

Download URL SudachiPy-0.5.2-cp38-cp38-macosx_10_14_x86_64.whl
Size 274.1 kB
Tags CPython 3.8 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
7a58e2f2004cfe9809cf0ebbacd22b06ad3ed6ff4474d21e3df29ea1d15ca51c
BLAKE2b-256 checksum
How to use checksums
81c654a6b496e2cffe16174e14778a04657db2cca80a04ecdd0eaf2f9ef4990e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

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

Download URL SudachiPy-0.5.2-cp37-cp37m-win_amd64.whl
Size 259.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
66d239d20517cab22519791efbfc2eccd15544ab6e58e910ffe604dfde3dbb9b
BLAKE2b-256 checksum
How to use checksums
0fb64ff1fe9737e8aec04bafb2f08c76df891b1936c19c3ec7013ec42053222c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

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

Download URL SudachiPy-0.5.2-cp37-cp37m-win32.whl
Size 226.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
40749b79d2acf73151397082c4b32302e3b8d0b3f5cb62faea8ac3bc86d0d989
BLAKE2b-256 checksum
How to use checksums
d68469e88d51a071d90a40afeb77582b3a0deced08299f5ca5977aba604dd239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

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

Download URL SudachiPy-0.5.2-cp37-cp37m-macosx_10_14_x86_64.whl
Size 273.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
d2fc2c28ec19159f104cc34389305aefc0d50186884ddc98ffa219e0e2e9a4e1
BLAKE2b-256 checksum
How to use checksums
477c9cd2aa7f91631ed21e89ad459da081e568fa80c14120f92d0f3267570844
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

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

Download URL SudachiPy-0.5.2-cp36-cp36m-win_amd64.whl
Size 278.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
7ea131c6000e8d60d1eb35b9149dc501feca7702b1ab0687a6be4f0b24d9171d
BLAKE2b-256 checksum
How to use checksums
9160c5a269ae1d4d930cf31b06c048ba05969b9a23b8b061f742a12d706c66a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.8

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

Download URL SudachiPy-0.5.2-cp36-cp36m-win32.whl
Size 240.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
f7b6a26fc04ae917c2fa285e7cebe93128c1eb43f0147b0563e5b29eab8601cd
BLAKE2b-256 checksum
How to use checksums
ff5415db8a820241d8ab742da659bd48e658b2f5fef4983316e4d995902a56b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.8

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

Download URL SudachiPy-0.5.2-cp36-cp36m-macosx_10_14_x86_64.whl
Size 291.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
8962f5eb648edda8fba73b7faacb19cc44397f527e5bf2c75f8910a548db096b
BLAKE2b-256 checksum
How to use checksums
23f8e0be3a77c7d615c38e486bcd7748568b3b5818a960a998b7b063538a56cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.13

Security for SudachiPy 0.5.2

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.2 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