Skip to main content

lindera_jumandic/
lib.rs

1#[cfg(feature = "embed-jumandic")]
2pub mod embedded;
3
4/// Dictionary name used as the host of `embedded://` dictionary URIs.
5pub const DICTIONARY_NAME: &str = "jumandic";
6/// Crate version, exposed through [`get_version`].
7const VERSION: &str = env!("CARGO_PKG_VERSION");
8
9/// Returns the version of this crate.
10///
11/// # Returns
12///
13/// The crate version string (e.g. `"7.1.0"`).
14pub fn get_version() -> &'static str {
15    VERSION
16}
17
18#[cfg(test)]
19mod tests {
20    use lindera_dictionary::dictionary::metadata::Metadata;
21
22    /// A line of mecab-jumandic is the surface, the two context ids and the
23    /// cost, then 品詞, 品詞細分類, 活用型, 活用形, 原形, 読み and the
24    /// semantic information of JUMAN: `あざまえな,1302,1302,10535,形容詞,*,
25    /// ナノ形容詞,ダ列基本連体形,あざまえだ,あざまえな,自動獲得:テキスト`.
26    /// The schema names follow that order.
27    #[test]
28    fn the_schema_follows_the_columns_of_mecab_jumandic() {
29        let metadata = match Metadata::load(include_bytes!("../metadata.json")) {
30            Ok(metadata) => metadata,
31            Err(err) => panic!("failed to load metadata.json: {err}"),
32        };
33        assert_eq!(metadata.name, super::DICTIONARY_NAME);
34        let schema = &metadata.dictionary_schema;
35        for (index, field) in [
36            "surface",
37            "left_context_id",
38            "right_context_id",
39            "cost",
40            "part_of_speech",
41            "part_of_speech_subcategory_1",
42            "conjugation_type",
43            "conjugation_form",
44            "base_form",
45            "reading",
46            "semantic_information",
47        ]
48        .into_iter()
49        .enumerate()
50        {
51            assert_eq!(schema.get_field_index(field), Some(index), "{field}");
52        }
53    }
54}