Skip to content

Commit

Permalink
check window_size
Browse files Browse the repository at this point in the history
  • Loading branch information
vbkaisetsu committed May 30, 2022
1 parent c8f7a4c commit d17062e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions vaporetto/src/char_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ impl CharScorer {
window_size: u8,
#[cfg(feature = "tag-prediction")] tag_ngram_model: Vec<TagNgramModel<String>>,
) -> Result<Self> {
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(
Expand Down
9 changes: 7 additions & 2 deletions vaporetto/src/type_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d17062e

Please sign in to comment.