lindera_dictionary/loader/
user_dictionary.rs

1use std::path::Path;
2
3use crate::LinderaResult;
4use crate::builder::DictionaryBuilder;
5use crate::dictionary::UserDictionary;
6use crate::util::read_file;
7
8/// Loader for user dictionaries with support for different input formats
9pub struct UserDictionaryLoader;
10
11impl UserDictionaryLoader {
12    /// Load user dictionary from a binary (.bin) file
13    pub fn load_from_bin<P: AsRef<Path>>(path: P) -> LinderaResult<UserDictionary> {
14        let data = read_file(path.as_ref())?;
15        UserDictionary::load(&data)
16    }
17
18    /// Load user dictionary from a CSV file
19    /// Requires a DictionaryBuilder to build the user dictionary from CSV format
20    pub fn load_from_csv<P: AsRef<Path>>(
21        builder: DictionaryBuilder,
22        path: P,
23    ) -> LinderaResult<UserDictionary> {
24        builder.build_user_dict(path.as_ref())
25    }
26}