jpreprocess/dictionary/mod.rs
1use std::path::PathBuf;
2
3use jpreprocess_core::JPreprocessResult;
4use lindera::dictionary::load_fs_dictionary;
5use lindera_dictionary::dictionary::Dictionary;
6
7pub mod kind;
8
9/// System dictionary configuration for JPreprocess.
10pub enum SystemDictionaryConfig {
11 /// Use self-contained dictionary. This is only valid if appropreate feature is enabled.
12 Bundled(kind::JPreprocessDictionaryKind),
13 /// Use pre-built external lindera/jpreprocess dictionary. The PathBuf is the path to dictionary.
14 ///
15 /// - When you are using lindera dictionary: Normal dictionary cannot be used;
16 /// it must contain the accent position and accent rule.
17 /// - When you are using jpreprocess dictionary: The JPreprocess version needs to be same as the
18 /// JPreprocess that built the dictionary.
19 File(PathBuf),
20}
21
22impl SystemDictionaryConfig {
23 pub fn load(self) -> JPreprocessResult<Dictionary> {
24 let dictionary = match self {
25 Self::Bundled(kind) => kind.load(),
26 Self::File(dictionary_path) => load_fs_dictionary(dictionary_path.as_path())?,
27 };
28
29 Ok(dictionary)
30 }
31}