diff --git a/CHANGELOG.md b/CHANGELOG.md index 090b8b08e..a3bd3ba4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Added - Binary serialization & deserialization support for FST caches. - Binary serialization & deserialization support for Compose FST op state table. +- Implement `WeaklyDivisibleSemiring` for `BooleanWeight` ## [0.8.0] - 2020-16-10 diff --git a/Cargo.lock b/Cargo.lock index f55b97ab2..155194e58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,7 +730,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rustfst" -version = "1.1.1" +version = "1.1.2" dependencies = [ "anyhow", "bimap", @@ -760,7 +760,7 @@ dependencies = [ [[package]] name = "rustfst-cli" -version = "1.1.1" +version = "1.1.2" dependencies = [ "anyhow", "clap", @@ -774,7 +774,7 @@ dependencies = [ [[package]] name = "rustfst-ffi" -version = "1.1.1" +version = "1.1.2" dependencies = [ "anyhow", "downcast-rs", diff --git a/rustfst/src/semirings/boolean_weight.rs b/rustfst/src/semirings/boolean_weight.rs index 60ece9a47..591e51b0f 100644 --- a/rustfst/src/semirings/boolean_weight.rs +++ b/rustfst/src/semirings/boolean_weight.rs @@ -2,6 +2,8 @@ use anyhow::Result; use crate::semirings::{CompleteSemiring, ReverseBack, Semiring, SemiringProperties, StarSemiring}; use std::borrow::Borrow; + +use super::{DivideType, WeaklyDivisibleSemiring}; /// Boolean semiring: (&, |, false, true). #[derive(Clone, Debug, PartialEq, PartialOrd, Default, Eq, Copy, Hash)] pub struct BooleanWeight { @@ -77,6 +79,15 @@ impl StarSemiring for BooleanWeight { } } +impl WeaklyDivisibleSemiring for BooleanWeight { + fn divide_assign(&mut self, rhs: &Self, _divide_type: DivideType) -> Result<()> { + if !rhs.value { + bail!("Division by 0") + } + Ok(()) // x / true == true + } +} + impl From for BooleanWeight { fn from(b: bool) -> Self { Self::new(b)