lindera_dictionary/
loader.rs1pub mod character_definition;
2pub mod connection_cost_matrix;
3pub mod metadata;
4pub mod prefix_dictionary;
5pub mod unknown_dictionary;
6pub mod user_dictionary;
7
8use std::path::Path;
9
10use crate::LinderaResult;
11use crate::dictionary::Dictionary;
12use crate::error::LinderaErrorKind;
13
14pub trait DictionaryLoader {
16 fn load(&self) -> LinderaResult<Dictionary> {
18 Err(LinderaErrorKind::Io.with_error(anyhow::anyhow!(
19 "This loader does not support load function"
20 )))
21 }
22
23 fn load_from_path(&self, path: &Path) -> LinderaResult<Dictionary> {
25 let _ = path;
26 Err(LinderaErrorKind::Io.with_error(anyhow::anyhow!(
27 "This loader does not support load_from_path function"
28 )))
29 }
30}
31
32pub struct FSDictionaryLoader;
33
34impl Default for FSDictionaryLoader {
35 fn default() -> Self {
36 Self::new()
37 }
38}
39
40impl FSDictionaryLoader {
41 pub fn new() -> Self {
42 Self
43 }
44
45 pub fn load_from_path<P: AsRef<Path>>(&self, dict_path: P) -> LinderaResult<Dictionary> {
46 Dictionary::load_from_path(dict_path.as_ref())
47 }
48}
49
50impl DictionaryLoader for FSDictionaryLoader {
51 fn load_from_path(&self, dict_path: &Path) -> LinderaResult<Dictionary> {
52 Dictionary::load_from_path(dict_path)
53 }
54}