diff --git a/python/extension/src/algorithms.rs b/python/extension/src/algorithms.rs index 195e1fcb..c141468e 100644 --- a/python/extension/src/algorithms.rs +++ b/python/extension/src/algorithms.rs @@ -1,4 +1,4 @@ -use ltp::{drop_get_entities, eisner, viterbi_decode_postprocessing}; +use ltp::utils::{drop_get_entities, eisner, viterbi_decode_postprocessing}; use pyo3::prelude::*; /// Convert Tags to Entities diff --git a/python/extension/src/hook.rs b/python/extension/src/hook.rs index 620640ab..9c8c24d0 100644 --- a/python/extension/src/hook.rs +++ b/python/extension/src/hook.rs @@ -1,4 +1,4 @@ -use ltp::hook::Hook; +use ltp::utils::hook::Hook; use pyo3::prelude::*; #[pyclass(module = "ltp_extension.algorithms", name = "Hook", subclass)] diff --git a/python/extension/src/stnsplit.rs b/python/extension/src/stnsplit.rs index 8babd0a6..5b933577 100644 --- a/python/extension/src/stnsplit.rs +++ b/python/extension/src/stnsplit.rs @@ -1,4 +1,4 @@ -use ltp::{stn_split_with_options, SplitOptions}; +use ltp::utils::{stn_split_with_options, SplitOptions}; use pyo3::prelude::*; use pyo3::types::{PyList, PyString}; use rayon::prelude::*; diff --git a/rust/ltp-cffi/src/stnsplit.rs b/rust/ltp-cffi/src/stnsplit.rs index 7a29bff7..74195f2a 100644 --- a/rust/ltp-cffi/src/stnsplit.rs +++ b/rust/ltp-cffi/src/stnsplit.rs @@ -1,5 +1,5 @@ use crate::Callback; -use ltp::stnsplit::{ +use ltp::utils::stnsplit::{ stn_split as r_stn_split, stn_split_with_options as r_stn_split_with_options, SplitOptions, }; use std::slice; diff --git a/rust/ltp/src/lib.rs b/rust/ltp/src/lib.rs index d4da425b..a43f2989 100644 --- a/rust/ltp/src/lib.rs +++ b/rust/ltp/src/lib.rs @@ -1,9 +1,5 @@ -pub mod eisner; -pub mod entities; -pub mod hook; pub mod perceptron; -pub mod stnsplit; -pub mod viterbi; +pub mod utils; pub use perceptron::{ Algorithm, CWSDefinition, NERDefinition, POSDefinition, PaMode, Perceptron, Trainer, @@ -18,7 +14,4 @@ pub type POSModel = SerdePOSModel; #[cfg(feature = "serialization")] pub type NERModel = SerdeNERModel; -pub use eisner::eisner; -pub use entities::{drop_get_entities, get_entities}; -pub use stnsplit::{stn_split, stn_split_with_options, SplitOptions}; -pub use viterbi::viterbi_decode_postprocessing; + diff --git a/rust/ltp/src/perceptron/definition/mod.rs b/rust/ltp/src/perceptron/definition/mod.rs index 85965ec2..bbe94e84 100644 --- a/rust/ltp/src/perceptron/definition/mod.rs +++ b/rust/ltp/src/perceptron/definition/mod.rs @@ -7,7 +7,7 @@ use std::collections::HashSet; use std::fmt::Debug; use std::io::Read; -use crate::get_entities; +use crate::utils::get_entities; use crate::perceptron::Sample; pub use cws::CWSDefinition; pub use ner::NERDefinition; diff --git a/rust/ltp/src/perceptron/model.rs b/rust/ltp/src/perceptron/model.rs index 2af857a8..14bb853e 100644 --- a/rust/ltp/src/perceptron/model.rs +++ b/rust/ltp/src/perceptron/model.rs @@ -259,7 +259,7 @@ impl Perceptron Perceptron where diff --git a/rust/ltp/src/eisner.rs b/rust/ltp/src/utils/eisner.rs similarity index 100% rename from rust/ltp/src/eisner.rs rename to rust/ltp/src/utils/eisner.rs diff --git a/rust/ltp/src/entities.rs b/rust/ltp/src/utils/entities.rs similarity index 100% rename from rust/ltp/src/entities.rs rename to rust/ltp/src/utils/entities.rs diff --git a/rust/ltp/src/hook.rs b/rust/ltp/src/utils/hook.rs similarity index 99% rename from rust/ltp/src/hook.rs rename to rust/ltp/src/utils/hook.rs index c8d9e783..a533310d 100644 --- a/rust/ltp/src/hook.rs +++ b/rust/ltp/src/utils/hook.rs @@ -378,7 +378,7 @@ mod tests { } #[test] - fn test_dag() { + fn test_dag() -> Result<()> { let mut dag = Dag::with_size_hint(5); let mut ans: Vec> = vec![Vec::new(); 5]; for i in 0..=3 { @@ -394,8 +394,10 @@ mod tests { assert_eq!(dag.size_hint_for_iterator, 4); for i in 0..=3 { - let edges: Vec = dag.iter_edges(i).collect(); + let edges: Vec = dag.iter_edges(i)?.collect(); assert_eq!(ans[i], edges); } + + Ok(()) } } diff --git a/rust/ltp/src/utils/mod.rs b/rust/ltp/src/utils/mod.rs new file mode 100644 index 00000000..e9bd4920 --- /dev/null +++ b/rust/ltp/src/utils/mod.rs @@ -0,0 +1,10 @@ +pub mod eisner; +pub mod entities; +pub mod hook; +pub mod stnsplit; +pub mod viterbi; + +pub use eisner::eisner; +pub use entities::{drop_get_entities, get_entities}; +pub use stnsplit::{stn_split, stn_split_with_options, SplitOptions}; +pub use viterbi::viterbi_decode_postprocessing; \ No newline at end of file diff --git a/rust/ltp/src/stnsplit.rs b/rust/ltp/src/utils/stnsplit.rs similarity index 100% rename from rust/ltp/src/stnsplit.rs rename to rust/ltp/src/utils/stnsplit.rs diff --git a/rust/ltp/src/viterbi.rs b/rust/ltp/src/utils/viterbi.rs similarity index 100% rename from rust/ltp/src/viterbi.rs rename to rust/ltp/src/utils/viterbi.rs