Skip to main content

lindera_dictionary/loader/
connection_cost_matrix.rs

1use std::path::Path;
2
3use crate::LinderaResult;
4use crate::dictionary::connection_cost_matrix::ConnectionCostMatrix;
5#[cfg(feature = "mmap")]
6use crate::util::mmap_file;
7use crate::util::read_file;
8
9/// Loader for connection cost matrix data from disk files.
10pub struct ConnectionCostMatrixLoader {}
11
12impl ConnectionCostMatrixLoader {
13    /// Load connection cost matrix from a file in the specified directory.
14    ///
15    /// # Arguments
16    ///
17    /// * `input_dir` - Path to the directory containing matrix.mtx.
18    ///
19    /// # Returns
20    ///
21    /// A `ConnectionCostMatrix` loaded from the file.
22    pub fn load(input_dir: &Path) -> LinderaResult<ConnectionCostMatrix> {
23        let data = read_file(input_dir.join("matrix.mtx").as_path())?;
24
25        Ok(ConnectionCostMatrix::load(data))
26    }
27
28    /// Load connection cost matrix using memory-mapped file.
29    ///
30    /// # Arguments
31    ///
32    /// * `input_dir` - Path to the directory containing matrix.mtx.
33    ///
34    /// # Returns
35    ///
36    /// A `ConnectionCostMatrix` loaded via memory mapping.
37    #[cfg(feature = "mmap")]
38    pub fn load_mmap(input_dir: &Path) -> LinderaResult<ConnectionCostMatrix> {
39        let data = mmap_file(input_dir.join("matrix.mtx").as_path())?;
40
41        Ok(ConnectionCostMatrix::load(data))
42    }
43}