# madi (마디)
순수 Rust 한국어 형태소 분석기 **madi** 의 라이브러리 진입점. 세종 품사 태그(NNG, VV, EF …)로 형태소를 나누고, 형태소 분석을 이용한 문장 분리도 합니다. Python 패키지는 `pip install madipy`(import `madi`).
A Korean morphological analyzer written in pure Rust (Sejong tag set, morpheme-aware sentence splitting). This crate is the library entry point (`Engine`); the command-line tool is `madi-cli`, the Python package is `madipy`.
## 사용 / Usage
```toml
[dependencies]
madi = "0.1" # 신경망 LM 포함 (feature nlm)
# madi = { version = "0.1", default-features = false } # KnLM 만
```
```rust
let cfg = madi::EngineConfig {
knlm: Some("knlm.bin".into()),
nlm: Some("model.nlm".into()),
lm_weight: 0.7,
nlm_weight: 0.3,
..madi::EngineConfig::new("madi.dict")
};
let engine = madi::Engine::load(&cfg)?; // Send + Sync — 스레드마다 worker() 하나
println!("{}", engine.version()); // 0.1.1+decdb.r3p.f11.k838c.n15e6.s0968 (모델·설정 확인용)
let mut w = engine.worker();
for s in w.analyze_doc("아버지가 방에 들어가신다. 감기는 무서운 병이다.") {
for t in &s.tokens {
print!("{}/{} ", t.form, t.tag.code());
}
println!();
}
```
### 0.2.0 에서 더한 것
```rust
let mut w = engine.worker();
for s in w.sentences("비가 온다. 우산을 챙겨라") { // 문장 구간 + 위치가 붙은 형태소
println!("{} [{}..{}]", s.text, s.start, s.end);
for m in &s.tokens { // madi::Morph { token, word, sent }
print!("{}/{}@{} ", m.token.form, m.token.tag.ko(), m.word);
}
}
for (score, toks) in w.analyze_nbest("감기는 무서운 병이다", 3) { /* 점수 큰 것부터 */ }
let (toks, ok) = w.analyze_pretokenized(text, &[madi::Pretoken { start: 0, end: 3, form: Some("감".into()), tag: Some("VV".into()) }]);
engine.add_user_word("케데헌", madi::Tag::NNG, Some(5.0)); // &mut Engine — 다음 worker 부터, 판본 문자열에 .u
```
`Tag::code()`(NNG) · `Tag::ko()`(일반명) · `Tag::name()`(일반명사) · `Tag::from_any("일반명")`, 원형은 `madi::lemma(&token)`.
모델 파일(`madi.dict`·`knlm.bin`·`model.nlm`·`precise.tlm`)은 크레이트에 들어 있지 않습니다. GitHub Release 에서 받습니다:
https://github.com/p14jeffwest/madi-release/releases (Python 패키지는 처음 쓸 때 자동으로 받습니다.)
Model files are not in the crate; download them from the release repository above.
## 이용 조건 / License
코드는 MIT 또는 Apache-2.0 중 택일입니다(저장소의 `LICENSE-MIT`·`LICENSE-APACHE`). 모델·사전 파일은 따로 배포하며 CC BY-SA 2.0 KR 입니다 — https://github.com/p14jeffwest/madi-release
Code: MIT OR Apache-2.0. Model files are distributed separately (CC BY-SA 2.0 KR), see the release repository above.