nlpstack.common.automaton module#

class nlpstack.common.automaton.DFA(state)[source]#

Bases: Generic[Symbol]

A deterministic finite automaton (DFA)

Parameters:

state (DFAState) –

accepts(symbols)[source]#
Return type:

bool

Parameters:

symbols (Iterable[Symbol]) –

classmethod from_symbol(symbol)[source]#

Create a DFA that accepts a single symbol.

Return type:

DFA

Parameters:

symbol (Symbol) –

show()[source]#
Return type:

None

step(state, symbol)[source]#
Return type:

Optional[DFAState]

Parameters:
  • state (DFAState[Symbol]) –

  • symbol (Symbol) –

class nlpstack.common.automaton.DFAState(is_final=False, transition=<factory>)[source]#

Bases: Generic[Symbol]

Parameters:
  • is_final (bool) –

  • transition (Dict[Symbol, DFAState]) –

acceptable_symbols()[source]#

Return acceptable symbols for this state.

Return type:

Set[TypeVar(Symbol, bound= Hashable)]

is_final: bool = False#
show()[source]#
Return type:

None

transition: Dict[TypeVar(Symbol, bound= Hashable), DFAState]#
class nlpstack.common.automaton.NFA(start, end)[source]#

Bases: Generic[Symbol]

A nondeterministic finite automaton (NFA)

Parameters:
closure()[source]#

Create an NFA that accepts the closure of the language of an NFA.

Return type:

NFA[TypeVar(Symbol, bound= Hashable)]

compile()[source]#

Compile a NFA into a DFA.

Return type:

DFA[TypeVar(Symbol, bound= Hashable)]

classmethod from_epsilon()[source]#

Create an NFA that accepts an empty string.

Return type:

NFA[TypeVar(Symbol, bound= Hashable)]

classmethod from_symbol(symbol)[source]#

Create an NFA that accepts a single symbol.

Return type:

NFA

Parameters:

symbol (Symbol) –

show()[source]#

Print the NFA in a human-readable format.

Return type:

None

class nlpstack.common.automaton.NFAState(is_final=False, transition=<factory>, epsilon_transitions=<factory>)[source]#

Bases: Generic[Symbol]

Parameters:
  • is_final (bool) –

  • transition (Dict[Symbol, NFAState]) –

  • epsilon_transitions (Set[NFAState]) –

allowed_transitions()[source]#

Return allowed transitions for this state.

Return type:

Dict[TypeVar(Symbol, bound= Hashable), Set[NFAState]]

epsilon_transitions: Set[NFAState]#
is_final: bool = False#
transition: Dict[TypeVar(Symbol, bound= Hashable), NFAState]#