1pub mod character_filter;
2pub mod dictionary;
3pub mod error;
4pub mod mode;
5pub mod segmenter;
6pub mod token;
7pub mod token_filter;
8pub mod tokenizer;
9
10use serde_json::Value;
11
12use crate::error::LinderaErrorKind;
13
14pub type LinderaResult<T> = lindera_dictionary::LinderaResult<T>;
15
16const VERERSION: &str = env!("CARGO_PKG_VERSION");
17
18pub fn get_version() -> &'static str {
19 VERERSION
20}
21
22fn parse_cli_flag(cli_flag: &str) -> LinderaResult<(&str, Value)> {
23 let (kind, json) = cli_flag.split_once(':').unwrap_or((cli_flag, ""));
24
25 let args: Value = serde_json::from_str(json)
26 .map_err(|err| LinderaErrorKind::Content.with_error(anyhow::anyhow!(err)))?;
27
28 Ok((kind, args))
29}
30
31#[cfg(test)]
32mod tests {
33 #[macro_export]
35 macro_rules! feature_test {
36 ($feature:literal, $test_name:ident, $test_body:block) => {
37 #[test]
38 #[cfg(feature = $feature)]
39 fn $test_name() {
40 $test_body
41 }
42 };
43 }
44
45 #[macro_export]
46 macro_rules! dictionary_test {
47 ($feature:literal, $dict_kind:expr, $test_name:ident, $test_body:expr) => {
48 #[test]
49 #[cfg(feature = $feature)]
50 fn $test_name() {
51 use $crate::dictionary::{DictionaryKind, load_dictionary_from_kind};
52
53 let dictionary = load_dictionary_from_kind($dict_kind).unwrap();
54 $test_body(dictionary);
55 }
56 };
57 }
58
59 #[macro_export]
60 macro_rules! token_filter_test {
61 ($feature:literal, $dict_kind:expr, $test_name:ident, $filter_setup:expr, $test_body:expr) => {
62 #[test]
63 #[cfg(feature = $feature)]
64 fn $test_name() {
65 use std::borrow::Cow;
66 use $crate::dictionary::{DictionaryKind, WordId, load_dictionary_from_kind};
67 use $crate::token::Token;
68 use $crate::token_filter::TokenFilter;
69
70 let dictionary = load_dictionary_from_kind($dict_kind).unwrap();
71 let filter = $filter_setup;
72 $test_body(filter, dictionary);
73 }
74 };
75 }
76}