1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! `mecab-sys` is the FFI wrapper for [MeCab](https://taku910.github.io/mecab/).
//! While [`ffi`] provides the FFI bindings, the top-level items are the safe wrapper for MeCab.
//!
//! # Examples
//!
//! ```
//! # fn analyze() {
//! use mecab_sys::Model;
//!
//! let model = Model::from_cli_arg(c"-d /path/to/your/dict -r /path/to/dictrc").unwrap();
//!
//! let tagger = model.new_tagger().unwrap();
//! let mut lattice = model.new_lattice().unwrap();
//!
//! let mut lattice = lattice.set_sentence("すもももももももものうち");
//! tagger.parse(&mut lattice).unwrap();
//!
//! for node in lattice.bos_node() {
//! let surface = node.surface();
//! let feat = node.feature();
//!
//! println!("{surface}: {feat}");
//! }
//! # }
//! ```
//!
//! ## Cursor API
//!
//! [`lattice.bos_node()`](`LatticeGuard::bos_node()`) returns a [`NodeCursor`], which can be
//! used either as an iterator and as a cursor of [`Node`]s.
//!
//! ```
//! # fn analyze() {
//! use mecab_sys::Model;
//!
//! let model = Model::from_cli_arg(c"-d /path/to/your/dict -r /path/to/dictrc").unwrap();
//!
//! let tagger = model.new_tagger().unwrap();
//! let mut lattice = model.new_lattice().unwrap();
//!
//! let mut lattice = lattice.set_sentence("すもももももももものうち");
//! tagger.parse(&mut lattice).unwrap();
//!
//! let mut cursor = lattice.bos_node();
//! assert!(cursor.curr().is_some_and(|node| node.kind().is_bos()));
//!
//! cursor.move_next();
//! cursor.move_next();
//! if let Some(node) = cursor.curr() {
//! let surface = node.surface();
//! let feat = node.feature();
//!
//! println!("{surface}: {feat}");
//! }
//!
//! cursor.move_prev();
//! if let Some(node) = cursor.curr() {
//! let surface = node.surface();
//! let feat = node.feature();
//!
//! println!("{surface}: {feat}");
//! }
//! # }
//! ```
//!
//! After you call `move_next()` on the EoS node, call `move_prev()` on the BoS node, or consume as
//! an iterator, then the cursor shifted to the "dead" state, never being back to the alive state.
//!
//! ```
//! # use mecab_sys::LatticeGuard;
//! # fn analyze(lattice: &LatticeGuard<'_, '_, '_>) {
//! let mut cursor = lattice.bos_node();
//! while cursor.curr().is_some_and(|node| !node.kind().is_eos()) {
//! cursor.move_next();
//! }
//! assert!(cursor.curr().is_some_and(|node| node.kind().is_eos()));
//!
//! // Call `move_next()` on the EoS node
//! cursor.move_next();
//! assert!(cursor.curr().is_none());
//!
//! // Never back to the original node
//! cursor.move_prev();
//! assert!(cursor.curr().is_none());
//!
//! let mut cursor = lattice.bos_node();
//! assert!(cursor.curr().is_some_and(|node| node.kind().is_bos()));
//!
//! // Call `move_prev()` on the BoS node
//! cursor.move_prev();
//! assert!(cursor.curr().is_none());
//!
//! // Never back to the original node
//! cursor.move_next();
//! assert!(cursor.curr().is_none());
//!
//! let mut cursor = lattice.bos_node();
//! // Consume the iterator, reaching at the EoS node
//! for _ in &mut cursor {}
//! assert!(cursor.curr().is_none());
//!
//! // Never back to alive nodes
//! cursor.move_prev();
//! assert!(cursor.curr().is_none());
//! # }
//! ```
/// The raw FFI layer for MeCab, generated from `mecab.h`.
pub use Model;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Error;