MCPcopy Index your code
hub / github.com/WorksApplications/sudachi.rs

github.com/WorksApplications/sudachi.rs @v0.6.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.11 ↗ · + Follow
1,179 symbols 3,359 edges 124 files 193 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sudachi.rs - 日本語 README

sudachi.rs logo

sudachi.rs は日本語形態素解析器 Sudachi の Rust 実装です。

English README

Python 版についてはこちらを参照してください: SudachiPy Documentation

TL;DR

Python 版のインストール:

pip install --upgrade 'sudachipy>=0.6.11'

Rust 版のインストール:

$ git clone https://github.com/WorksApplications/sudachi.rs.git
$ cd ./sudachi.rs

$ cargo build --release
$ cargo install --path sudachi-cli/
$ ./fetch_dictionary.sh

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

利用例

複数粒度での分割

$ echo 選挙管理委員会 | sudachi
選挙管理委員会  名詞,固有名詞,一般,*,*,*        選挙管理委員会
EOS

$ echo 選挙管理委員会 | sudachi --mode A
選挙    名詞,普通名詞,サ変可能,*,*,*    選挙
管理    名詞,普通名詞,サ変可能,*,*,*    管理
委員    名詞,普通名詞,一般,*,*,*        委員
会      名詞,普通名詞,一般,*,*,*        会
EOS

正規化表記

$ echo 打込む かつ丼 附属 vintage | sudachi
打込む  動詞,一般,*,*,五段-マ行,終止形-一般     打ち込む
        空白,*,*,*,*,*
かつ丼  名詞,普通名詞,一般,*,*,*        カツ丼
        空白,*,*,*,*,*
附属    名詞,普通名詞,サ変可能,*,*,*    付属
        空白,*,*,*,*,*
vintage 名詞,普通名詞,一般,*,*,*        ビンテージ
EOS

分かち書き出力

$ cat lemon.txt
えたいの知れない不吉な塊が私の心を始終圧えつけていた。
焦躁と言おうか、嫌悪と言おうか――酒を飲んだあとに宿酔があるように、酒を毎日飲んでいると宿酔に相当した時期がやって来る。
それが来たのだ。これはちょっといけなかった。

$ sudachi --wakati lemon.txt
えたい の 知れ ない 不吉 な 塊 が 私 の 心 を 始終 圧え つけ て い た 。
焦躁 と 言おう か 、 嫌悪 と 言おう か ― ― 酒 を 飲ん だ あと に 宿酔 が ある よう に 、 酒 を 毎日 飲ん で いる と 宿酔 に 相当 し た 時期 が やっ て 来る 。
それ が 来 た の だ 。 これ は ちょっと いけ なかっ た 。

セットアップ

sudachi.rs 本体に加え、デフォルトで使用するプラグイン、また辞書が必要になります。※パッケージには辞書が含まれていません。

1. ソースコードの取得

git clone https://github.com/WorksApplications/sudachi.rs.git

2. Sudachi 辞書のダウンロード

WorksApplications/SudachiDictから辞書の zip ファイル( smallcorefull から一つ選択)し、解凍して、必要であれば中にある system_*.dic ファイルをわかりやすい位置に置いてください。 デフォルトの設定ファイルでは、辞書ファイルが resources/system.dic に存在していると指定しています(ファイル名が system.dic に変わっていることに注意)。

ダウンロードスクリプト

上記のように手動で設置する以外に、レポジトリにあるスクリプトを使って自動的に辞書をダウンロードし resources/system.dic として設置することもできます。

# fetch latest core dictionary
./fetch_dictionary.sh

# fetch dictionary of specified version and type
./fetch_dictionary.sh 20241021 small

3. ビルド

ビルド(デフォルト)

--all フラグを使って付属のプラグインもまとめてビルドすることができます。

cargo build --release

ビルド(辞書バイナリの埋め込み)

以下は現在未対応となっています https://github.com/WorksApplications/sudachi.rs/issues/35 をご参考ください。

bake_dictionary フィーチャーフラグを立ててビルドすることで、辞書ファイルをバイナリに埋め込むことができます。 これによってビルドされた実行ファイルは、辞書バイナリを内包しています。 オプションや設定ファイルで辞書が指定されなかった場合、この内包辞書が使用されます。

ビルド時、埋め込む辞書へのパスを SUDACHI_DICT_PATH 環境変数によって指定する必要があります。 このパスは絶対パスもしくは sudachi.rs ディレクトリからの相対パスで指定してください。

Unix-like システムでの例:

# resources/system.dic への辞書ダウンロード
$ ./fetch_dictionary.sh

# bake_dictionary フィーチャーフラグ付きでビルド (辞書を相対パスで指定)
$ env SUDACHI_DICT_PATH=resources/system.dic cargo build --release --features bake_dictionary

# もしくは

# bake_dictionary フィーチャーフラグ付きでビルド (辞書を絶対パスで指定)
$ env SUDACHI_DICT_PATH=/path/to/my-sudachi.dic cargo build --release --features bake_dictionary

4. インストール

$ cd sudachi.rs/
$ cargo install --path sudachi-cli/

$ which sudachi
/Users/<USER>/.cargo/bin/sudachi

$ sudachi -h
sudachi 0.6.0
A Japanese tokenizer
...

利用方法

$ sudachi -h
A Japanese tokenizer

Usage: sudachi [OPTIONS] [FILE] [COMMAND]

Commands:
  build
          Builds system dictionary
  ubuild
          Builds user dictionary
  dump

  help
          Print this message or the help of the given subcommand(s)

Arguments:
  [FILE]
          Input text file: If not present, read from STDIN

Options:
  -r, --config-file <CONFIG_FILE>
          Path to the setting file in JSON format
  -p, --resource_dir <RESOURCE_DIR>
          Path to the root directory of resources
  -m, --mode <MODE>
          Split unit: "A" (short), "B" (middle), or "C" (Named Entity) [default: C]
  -o, --output <OUTPUT_FILE>
          Output text file: If not present, use stdout
  -a, --all
          Prints all fields
  -w, --wakati
          Outputs only surface form
  -d, --debug
          Debug mode: Print the debug information
  -l, --dict <DICTIONARY_PATH>
          Path to sudachi dictionary. If None, it refer config and then baked dictionary
      --split-sentences <SPLIT_SENTENCES>
          How to split sentences [default: yes]
  -h, --help
          Print help (see more with '--help')
  -V, --version
          Print version

出力

タブ区切りで出力されます。 デフォルトは以下の情報が含まれます。

  • 表層形
  • 品詞(コンマ区切り)
  • 正規化表記

オプションで -a (--all) を指定すると以下の情報が追加されます。

  • 辞書形
  • 読み
  • 辞書 ID
  • 0 システム辞書
  • 1 ユーザー辞書
  • -1 未知語(辞書に含まれない単語)
  • 同義語グループ ID
  • (OOV) 未知語(辞書に含まれない単語)の場合のみ
$ echo "外国人参政権" | sudachi -a
外国人参政権    名詞,普通名詞,一般,*,*,*        外国人参政権    外国人参政権    ガイコクジンサンセイケン      0       []
EOS
echo "阿quei" | sudachipy -a
阿      名詞,普通名詞,一般,*,*,*        阿      阿              -1      []      (OOV)
quei    名詞,普通名詞,一般,*,*,*        quei    quei            -1      []      (OOV)
EOS

オプションで -w (--wakati) を指定すると代わりに表層形のみをスペース区切りで出力します。

$ echo "外国人参政権" | sudachi -m A -w
外国 人 参政 権

ToDo

リファレンス

Sudachi

Rust による形態素解析器の実装

ロゴ

Extension points exported contracts — how you extend this code

PluginCategory (Interface)
A category of Plugins [4 implementers]
sudachi/src/plugin/loader.rs
MorphemeProjection (Interface)
(no doc) [5 implementers]
python/src/projection.rs
Analysis (Interface)
(no doc) [3 implementers]
sudachi-cli/src/analysis.rs
DictionaryAccess (Interface)
Provides access to dictionary data [4 implementers]
sudachi/src/analysis/stateless_tokenizer.rs
SudachiOutput (Interface)
(no doc) [2 implementers]
sudachi-cli/src/output.rs
InputTextPlugin (Interface)
Trait of plugin to modify the input text before tokenization [3 implementers]
sudachi/src/plugin/input_text/mod.rs
OovProviderPlugin (Interface)
Trait of plugin to provide oov node during tokenization [3 implementers]
sudachi/src/plugin/oov/mod.rs
RightId (Interface)
Accessor trait for right connection id [3 implementers]
sudachi/src/analysis/node.rs

Core symbols most depended-on inside this repo

len
called by 133
sudachi/src/analysis/mlist.rs
tokenize
called by 76
python/src/pretokenizer.rs
surface
called by 73
python/src/morpheme.rs
iter
called by 44
sudachi/src/analysis/mlist.rs
as_ref
called by 41
sudachi/src/dic/storage.rs
clear
called by 36
sudachi/src/plugin/path_rewrite/join_numeric/numeric_parser/mod.rs
to_string
called by 36
sudachi/src/plugin/path_rewrite/join_numeric/numeric_parser/string_number.rs
insert
called by 36
sudachi/src/analysis/lattice.rs

Shape

Method 672
Function 342
Class 122
Enum 23
Interface 20

Languages

Rust90%
Python10%

Modules by API surface

sudachi/src/config.rs39 symbols
python/src/morpheme.rs39 symbols
sudachi/src/input_text/buffer/mod.rs36 symbols
sudachi/src/analysis/node.rs31 symbols
sudachi/src/dic/character_category.rs29 symbols
sudachi/src/analysis/mlist.rs28 symbols
sudachi/src/input_text/buffer/edit.rs24 symbols
python/src/dictionary.rs24 symbols
sudachi/src/hash.rs23 symbols
sudachi/src/dic/lexicon/word_infos.rs23 symbols
sudachi/src/dic/grammar.rs23 symbols
sudachi/src/analysis/morpheme.rs23 symbols

For agents

$ claude mcp add sudachi.rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact