Skip to main content

Explicit

Struct Explicit 

Source
pub struct Explicit { /* private fields */ }
Expand description

A fully materialized bottom-up tree automaton.

Explicit stores transition rules in lookup tables. It is the fastest representation when all rules are known ahead of time or after an implicit automaton has been materialized. Rules with arity 0, 1, and 2 use separate compact tables because those are the common hot paths.

Build values with ExplicitBuilder. Every transition rule has a weight; callers that do not have natural weights can use 1.0.

Implementations§

Source§

impl Explicit

Source

pub fn application_summary(&self) -> AutomatonSummary

Return an owned summary without exposing internal indexes.

Source

pub fn language_cardinality(&self) -> LanguageCardinality

Return the number of accepted derivation trees without enumerating them.

Source

pub fn resolve_rules( &self, state_name: impl FnMut(StateId) -> String, symbol_name: impl FnMut(Symbol) -> String, ) -> Vec<ResolvedRule>

Resolve rules with caller-supplied state and symbol naming.

Source

pub fn resolved_rule( &self, index: usize, state_name: impl FnMut(StateId) -> String, symbol_name: impl FnMut(Symbol) -> String, ) -> ResolvedRule

Resolve a single rule by index with caller-supplied naming.

Source§

impl Explicit

Source

pub fn num_states(&self) -> u32

Return the number of allocated states.

Source

pub fn num_rules(&self) -> usize

Return the number of transition rules in this automaton.

Source

pub fn is_empty(&self) -> bool

Return true if no tree can be accepted by this automaton.

This computes reachable states from nullary rules and checks whether any accepting state is reachable.

Source

pub fn reachable_states(&self) -> FixedBitSet

Compute states reachable from nullary rules by saturation.

A state is reachable if some finite tree can receive that state at its root. This is often useful for pruning or quick emptiness checks. The result is cached after the first call because explicit automata are immutable.

Source

pub fn rules(&self) -> impl Iterator<Item = Rule<'_>>

Iterate over all transition rules.

The order is stable for a fixed automaton but should not be treated as a semantic ordering.

Source

pub fn rules_topdown(&self, parent: StateId) -> impl Iterator<Item = Rule<'_>>

Iterate over rules with the given parent/result state.

Source

pub fn rule(&self, rule_idx: usize) -> Rule<'_>

Return the transition rule at the given index.

Provides O(1) indexed access to a borrowed view of a rule; the children slice is not copied. The index must be less than Self::num_rules; passing an out-of-bounds index panics. Rule order matches the order produced by Self::rules.

Source§

impl Explicit

Source

pub fn sorted_language(&self) -> SortedLanguageIterator<'_>

Iterate over accepted trees in descending rule-weight product order.

Source§

impl Explicit

Source

pub fn viterbi(&self) -> Option<ViterbiTree>

Compute the highest-weighted accepted tree.

This is a direct one-best dynamic program for acyclic parse charts. It deliberately avoids the k-best sorted-language machinery when callers only need the best derivation. Cyclic dependencies on the active DFS path are ignored: for PCFG-style rule weights below one, traversing a cycle cannot improve a finite derivation. Direct self-loops are skipped for the same reason, matching Alto’s convention.

Source

pub fn viterbi_with<S: WeightScorer>(&self, scorer: &S) -> Option<ViterbiTree>

Compute the highest-scoring accepted tree under scorer.

Trait Implementations§

Source§

impl BottomUpTa for Explicit

Source§

type State = StateId

State type carried by the automaton. Read more
Source§

fn step(&self, f: Symbol, children: &[StateId], out: &mut dyn FnMut(StateId))

Report all possible parent states for f(children...). Read more
Source§

fn is_accepting(&self, q: &StateId) -> bool

Return whether q is an accepting state. Read more
Source§

impl Clone for Explicit

Source§

fn clone(&self) -> Explicit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CondensedTa for Explicit

Source§

fn condensed_rules(&self, out: &mut dyn FnMut(&[StateId], &SymbolSet, StateId))

Enumerate every distinct (children, result) pair, reporting the set of symbols that have that shape. Read more
Source§

fn condensed_nullary_rules(&self, out: &mut dyn FnMut(&SymbolSet, StateId))

Enumerate condensed nullary rules. Read more
Source§

fn condensed_rules_by_child( &self, position: usize, state: &StateId, out: &mut dyn FnMut(&[StateId], &SymbolSet, StateId), )

Enumerate condensed rules whose child at position is state. Read more
Source§

impl CondensedTopDownTa for Explicit

Source§

fn condensed_rules_by_parent( &self, parent: &StateId, out: &mut dyn FnMut(&SymbolSet, &[StateId]), )

Report every condensed rule symbols(children...) -> parent. Read more
Source§

fn condensed_initial_states(&self, out: &mut dyn FnMut(StateId))

Report initial states of the top-down view.
Source§

impl Debug for Explicit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DetBottomUpTa for Explicit

Source§

fn step_det(&self, f: Symbol, children: &[StateId]) -> Option<StateId>

Return the unique result state, or None if no transition exists. Read more
Source§

fn det_group(&self, f: Symbol) -> u32

Group key for symbols that share a transition function. Read more
Source§

impl IndexedBottomUpTa for Explicit

Source§

fn step_partial( &self, f: Symbol, position: usize, state_at_position: &StateId, out: &mut dyn FnMut(&[StateId], StateId), )

Report every rule f(children...) -> q where children[position] equals state_at_position. Read more
Source§

impl StateUniverse for Explicit

Source§

fn all_states(&self, out: &mut dyn FnMut(StateId))

Report every state in the finite universe exactly once.
Source§

impl TopDownTa for Explicit

Source§

fn step_topdown( &self, parent: &StateId, out: &mut dyn FnMut(Symbol, &[StateId]), )

Report every rule f(children...) -> parent. Read more
Source§

fn initial_states(&self, out: &mut dyn FnMut(StateId))

Report the initial states of the top-down view. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.