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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
//! # mlmorph
//!
//! A Rust implementation of the Malayalam Morphological Analyzer using Finite State Transducer technology.
//!
//! ## Overview
//!
//! `mlmorph` is a Rust port of the [mlmorph](https://gitlab.com/smc/mlmorph) Malayalam morphological
//! analyzer and generator. It provides fast and efficient morphological analysis and generation for
//! Malayalam text using Finite State Transducers (FST) built with the Stuttgart Finite State Toolkit (SFST).
//!
//! This library can:
//! - **Analyze** Malayalam words to identify their morphological structure
//! - **Generate** word forms from morphological descriptions
//! - **Detect** foreign words in Malayalam text
//! - **Normalize** Malayalam text using standard transformations
//!
//! ## Features
//!
//! - **Fast Performance**: Rust implementation provides excellent performance
//! - **Morphological Analysis**: Break down Malayalam words into morphemes and POS tags
//! - **Word Generation**: Generate word forms from morphological templates
//! - **Foreign Word Detection**: Identify non-Malayalam words in text
//! - **Text Normalization**: Standardize Malayalam text representations
//! - **CLI Interface**: Command-line tool for batch processing
//! - **Library API**: Easy-to-use Rust API for integration
//!
//! ## Quick Start
//!
//! ### Morphological Analysis
//!
//! ```rust
//! use mlmorph::Analyser;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let analyser = Analyser::new()?;
//!
//! // Analyze a Malayalam word
//! let results = analyser.analyse("കേരളത്തിന്റെ", true, true)?;
//!
//! for (analysis, weight) in results {
//! println!("Analysis: {} (weight: {})", analysis, weight);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ### Word Generation
//!
//! ```rust
//! use mlmorph::Generator;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let generator = Generator::new()?;
//!
//! // Generate word forms from morphological description
//! let results = generator.generate("കേരളം<np><genitive>", true)?;
//!
//! for (word, weight) in results {
//! println!("Generated: {} (weight: {})", word, weight);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ### Foreign Word Detection
//!
//! ```rust
//! use mlmorph::check_foreign_word;
//!
//! let word = "computer";
//! let is_foreign = check_foreign_word(word);
//!
//! if is_foreign == 1 {
//! println!("{} is a foreign word", word);
//! } else {
//! println!("{} is a Malayalam word", word);
//! }
//! ```
//!
//! ### Text Normalization
//!
//! ```rust
//! use mlmorph::normalize;
//!
//! let text = "ണ്";
//! let normalized = normalize(text);
//! assert_eq!(normalized, "ൺ");
//! ```
//!
//! ## Performance
//!
//! The Rust implementation provides significant performance improvements over the Python version:
//!
//! - **Analysis**: ~10x faster than Python implementation
//! - **Generation**: ~8x faster than Python implementation
//! - **Memory**: Lower memory footprint
//! - **Concurrency**: Safe for concurrent use across threads
//!
//! ## Requirements
//!
//! - **SFST Data**: The library requires the compiled Malayalam FST file (`data/malayalam.a`)
//! - **Rust**: Version 1.70 or higher
pub use Analyser;
pub use check_foreign_word;
pub use Generator;
pub use normalize;
use ;
use Sfst;
use fs;
use TempDir;
/// Represents a single morpheme in the morphological analysis.
///
/// A morpheme is the smallest grammatical unit in a language. Each morpheme
/// consists of a root word and associated part-of-speech (POS) tags.
///
/// # Examples
///
/// ```rust
/// use mlmorph::Morpheme;
///
/// let morpheme = Morpheme {
/// root: "കേരളം".to_string(),
/// pos: vec!["np".to_string(), "genitive".to_string()],
/// };
///
/// assert_eq!(morpheme.root, "കേരളം");
/// assert_eq!(morpheme.pos.len(), 2);
/// ```
/// Represents the complete parsed analysis of a word.
///
/// Contains all morphemes that make up the word and the overall weight
/// of the analysis. Lower weights indicate more preferred analyses.
///
/// # Examples
///
/// ```rust
/// use mlmorph::{ParsedAnalysis, Morpheme};
///
/// let analysis = ParsedAnalysis {
/// morphemes: vec![
/// Morpheme {
/// root: "കേരളം".to_string(),
/// pos: vec!["np".to_string(), "genitive".to_string()],
/// }
/// ],
/// weight: 179,
/// };
///
/// assert_eq!(analysis.morphemes.len(), 1);
/// assert_eq!(analysis.weight, 179);
/// ```
/// Result type for morphological analysis operations.
///
/// Contains the analysis string and its associated weight.
/// The analysis string uses angle brackets to denote morphological tags.
///
/// # Format
///
/// The analysis string follows the format: `root<tag1><tag2>...`
///
/// # Examples
///
/// ```rust
/// use mlmorph::AnalysisResult;
///
/// let result: AnalysisResult = ("കേരളം<np><genitive>".to_string(), 179);
/// let (analysis, weight) = result;
///
/// assert_eq!(analysis, "കേരളം<np><genitive>");
/// assert_eq!(weight, 179);
/// ```
pub type AnalysisResult = ;
/// Result type for word generation operations.
///
/// Contains the generated word and its associated weight.
/// Lower weights indicate more preferred generations.
///
/// # Examples
///
/// ```rust
/// use mlmorph::GenerationResult;
///
/// let result: GenerationResult = ("കേരളത്തിന്റെ".to_string(), 179);
/// let (word, weight) = result;
///
/// assert_eq!(word, "കേരളത്തിന്റെ");
/// assert_eq!(weight, 179);
/// ```
pub type GenerationResult = ;