sudachi.rs - 日本語 README

March 6, 2026 · View on GitHub

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 による形態素解析器の実装

ロゴ