From b22a5b38161fbc4a0bb9e472d42f78311b73741e Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 28 Feb 2023 15:37:14 +0800 Subject: Add no_item parameter. * chain/src/default.rs: * chain/src/lib.rs: Add a parameter that controls whether or not the chain-rule machine computes the item derivation forest as well. Sometimes we only need to recognize whether an input belongs to the grammar, but do not care about the derivations. This parameter can speed up the machine in that case. --- chain/src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'chain/src/lib.rs') diff --git a/chain/src/lib.rs b/chain/src/lib.rs index d7fc519..9de1df7 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -258,11 +258,9 @@ pub trait Chain: LabelExtGraph { /// An iterator that iterates all layers that need to be merged. type DerIter: Iterator; - // FIXME: Add a parameter to control whether to manipulate the - // forests or not. - /// Take the derivative by a terminal `t` at position `pos`. - fn derive(&mut self, t: usize, pos: usize) -> Result; + fn derive(&mut self, t: usize, pos: usize, no_item: bool) + -> Result; /// Take the union of all derivatives. fn union(&mut self, der_iter: Self::DerIter) -> Result, Self::Error> { @@ -279,8 +277,18 @@ pub trait Chain: LabelExtGraph { /// Use chain rule to compute the derivative with respect to a /// terminal. - fn chain(&mut self, t: usize, pos: usize) -> Result<(), Self::Error> { - let der_iter = self.derive(t, pos)?; + /// + /// # Arguments + /// + /// The argument `t` is the terminal we computet the derivative + /// with. + /// + /// The argument `pos` is the position within the input. + /// + /// The argument `no_item` determines whether we want the item + /// derivation forest as well. + fn chain(&mut self, t: usize, pos: usize, no_item: bool) -> Result<(), Self::Error> { + let der_iter = self.derive(t, pos, no_item)?; let edges = self.union(der_iter)?; -- cgit v1.2.3-18-g5258