プロジェクト構成

Lindera は複数のクレートで構成される Cargo ワークスペースとして組織されています。

ディレクトリ構成

lindera/
├── lindera-crf/            # CRF エンジン(pure Rust、no_std)
├── lindera-dictionary/     # 辞書ベースライブラリ
├── lindera-trainer/        # CRF ベースの辞書学習
├── lindera/                # ファサードクレート(lindera-segmenter と lindera-analysis を再エクスポート)。tests・examples・benches を含む
├── lindera-segmenter/      # 形態素分割ライブラリ(Segmenter API)
├── lindera-analysis/       # 分析チェーン(character/token filter・tokenizer)
├── lindera-cli/            # CLI ツール
├── lindera-binding/        # 言語バインディングが共有するFFI非依存のヘルパー
├── lindera-ipadic/         # IPADIC 辞書(日本語)
├── lindera-ipadic-neologd/ # IPADIC NEologd 辞書(日本語)
├── lindera-unidic/         # UniDic 辞書(日本語)
├── lindera-sudachidict/    # SudachiDict 辞書(日本語)
├── lindera-ko-dic/         # ko-dic 辞書(韓国語)
├── lindera-cc-cedict/      # CC-CEDICT 辞書(中国語)
├── lindera-jieba/          # Jieba 辞書(中国語)
├── lindera-python/         # Python バインディング(PyO3)
├── lindera-nodejs/         # Node.js バインディング(NAPI-RS)
├── lindera-ruby/           # Ruby バインディング(Magnus + rb-sys)
├── lindera-php/            # PHP バインディング(ext-php-rs)
├── lindera-wasm/           # WebAssembly バインディング(wasm-bindgen)
├── resources/              # テストリソースとサンプルデータ
└── docs/                   # ドキュメント(mdBook)

クレートの説明

コアクレート

lindera-crf

条件付き確率場(CRF)の pure Rust 実装です。no_std 環境をサポートします。高速なゼロコピーシリアライゼーションに rkyv を使用します。辞書学習で使用される統計学習エンジンを提供します。

lindera-dictionary

辞書のベースライブラリです。辞書の読み込み、ビルド、クエリ機能を提供します。

lindera-trainer

カスタム辞書作成のための CRF 学習パイプラインです。lindera-dictionary のランタイム型と lindera-crf エンジンの上に構築されています。通常は lindera facade の train feature 経由で利用します(lindera::dictionary::trainer として再エクスポート)。

モジュール役割
config.rs設定管理(種辞書、char.def、feature.def、rewrite.def)
corpus.rs学習コーパスの処理
feature_extractor.rs素性テンプレートの解析と素性 ID 管理
feature_rewriter.rsMeCab 互換の素性書き換え(3セクション形式)
model.rs学習済みモデルの保存、シリアライゼーション、辞書出力

lindera-segmenter

形態素分割ライブラリです(v6 までは lindera として公開)。辞書クレートを統合し、Segmenter API を提供します。dictionary モジュールからは lindera-dictionary の生モジュール(builder・core・loader・viterbi など)も再エクスポートされます。

lindera

ファサードクレートで、Rust ユーザーが追加する唯一の依存です。lindera-segmenter の全モジュールを再エクスポートし、デフォルトで有効な analysis feature により lindera-analysis を lindera::analysis として提供します。このディレクトリには公開パスを検証する統合テスト・サンプル・ベンチマークも置かれています。

lindera-analysis

lindera-segmenter の上に構築されたLucene風の分析チェーンです(ファサード経由では lindera::analysis として利用します)。文字フィルタ、トークンフィルタ、およびそれらを Segmenter の周りで組み合わせる Tokenizer を提供します。

lindera-cli

トークナイズ、辞書学習、エクスポート、ビルドのためのコマンドラインインターフェースです。デフォルトで train feature が有効です。

lindera-binding

5つの言語バインディング(lindera-python、lindera-nodejs、lindera-ruby、lindera-php、lindera-wasm)すべてが共有するFFI非依存のヘルパーです。各バインディングがそれぞれの言語のネイティブAPIでラップするコアのトークナイザー・スキーマ・メタデータ層を提供します。lindera ファサードに依存します。

辞書クレート

各辞書クレートには、特定の言語と辞書ソースのビルド済み辞書データが含まれます。

クレート言語辞書ソース
lindera-ipadic日本語IPADIC
lindera-ipadic-neologd日本語IPADIC NEologd(拡張語彙)
lindera-unidic日本語UniDic
lindera-sudachidict日本語SudachiDict
lindera-ko-dic韓国語ko-dic
lindera-cc-cedict中国語CC-CEDICT
lindera-jieba中国語Jieba

バインディング

lindera-python

PyO3 で構築された Python バインディングです。Lindera のトークナイザー API を Python アプリケーションに公開します。

lindera-nodejs

NAPI-RS で構築された Node.js バインディングです。Lindera のトークナイザー API を Node.js アプリケーションに公開します。

lindera-ruby

Magnus と rb-sys で構築された Ruby バインディングです。Lindera のトークナイザー API を Ruby gem として公開します。

lindera-php

ext-php-rs で構築された PHP バインディングです。Lindera のトークナイザー API を PHP 拡張として公開します。拡張名は lindera で、PIE 向けに Packagist へ lindera/lindera として公開します。パッケージの composer.json はリポジトリのルートにあり、PIE を lindera-php/ に向けます。そこで config.m4 と Makefile.frag が phpize ビルドの中で cargo build を実行します。

lindera-wasm

wasm-bindgen で構築された WebAssembly バインディングです。ブラウザと Node.js でのトークナイズを可能にします。

その他のディレクトリ

resources/

テストスイートで使用されるサンプル辞書、ユーザー辞書、テストコーパスなどのテストリソースです。

docs/

mdBook で構築されたユーザー向けドキュメントです。目次は docs/src/SUMMARY.md で定義されています。日本語翻訳は docs/ja/ 配下にあります。

lindera/examples/ と lindera-analysis/examples/

一般的な使用パターンを示す実行可能なサンプルプログラムです。以下のコマンドで実行できます:

cargo run -p lindera --features=embed-ipadic --example=segment
cargo run -p lindera-analysis --features=embed-ipadic --example=tokenize