diff --git a/vaporetto/src/char_scorer.rs b/vaporetto/src/char_scorer.rs index 41d00b8c..8e9cf1b3 100644 --- a/vaporetto/src/char_scorer.rs +++ b/vaporetto/src/char_scorer.rs @@ -92,6 +92,12 @@ impl CharScorer { window_size: u8, #[cfg(feature = "tag-prediction")] tag_ngram_model: Vec>, ) -> Result { + if window_size == 0 { + return Err(Vaporetto::invalid_model( + "char_window_size must be a positive value", + )); + } + #[cfg(feature = "tag-prediction")] if tag_ngram_model.is_empty() { Ok(Self::Boundary(CharScorerBoundary::new( diff --git a/vaporetto/src/type_scorer.rs b/vaporetto/src/type_scorer.rs index c7eff84a..f613ab28 100644 --- a/vaporetto/src/type_scorer.rs +++ b/vaporetto/src/type_scorer.rs @@ -14,7 +14,7 @@ use alloc::vec::Vec; use bincode::{BorrowDecode, Encode}; -use crate::errors::Result; +use crate::errors::{Result, VaporettoError}; use crate::ngram_model::NgramModel; use crate::sentence::Sentence; @@ -105,11 +105,16 @@ impl TypeScorer { #[cfg(feature = "tag-prediction")] if tag_ngram_model.is_empty() { match window_size { + 0 => Err(Vaporetto::invalid_model( + "type_window_size must be a positive value", + )), + #[cfg(feature = "cache-type-score")] - 0..=CACHE_MAX_WINDOW_SIZE => Ok(Self::BoundaryCache(TypeScorerBoundaryCache::new( + 1..=CACHE_MAX_WINDOW_SIZE => Ok(Self::BoundaryCache(TypeScorerBoundaryCache::new( ngram_model, window_size, )?)), + _ => Ok(Self::Boundary(TypeScorerBoundary::new( ngram_model, window_size,