fsm

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseDomain added in v0.5.0

type BaseDomain struct {
	StateTable      StateTable `json:"state_table"`
	CommandList     []string   `json:"command_list"`
	DefaultMessages Defaults   `json:"default_messages"`
}

BaseDomain contains the data required for a minimally functioning FSM

type CmdStateTuple

type CmdStateTuple struct {
	Cmd   string
	State int
}

CmdStateTuple is a tuple of Command and State TODO: Document how the CmdStateTuple works

type Defaults added in v0.3.0

type Defaults struct {
	Unknown string `yaml:"unknown" json:"unknown"`
	Unsure  string `yaml:"unsure" json:"unsure"`
	Error   string `yaml:"error" json:"error"`
}

Defaults set the messages that will be returned when Unknown, Unsure or Error events happen during FSM execution

type Domain

type Domain struct {
	BaseDomain
	TransitionTable TransitionTable
	SlotTable       SlotTable
}

Domain contains BaseDomain plus the functions required for a fully functioning FSM

func NewDomain added in v0.5.1

func NewDomain(commands, states []string, functions []Function, defaults Defaults) *Domain

NewDomain initializes a new Domain

func (*Domain) NoFuncs

func (d *Domain) NoFuncs() *BaseDomain

NoFuncs returns a Domain without TransitionFunc items in order to serialize it for extensions

type ErrUnknownCommand added in v0.6.0

type ErrUnknownCommand struct {
	Msg string
}

ErrUnknownCommand is returned by the FSM when a function command was found by the classifier but the state transition is unknown or not valid

func (*ErrUnknownCommand) Error added in v0.6.0

func (e *ErrUnknownCommand) Error() string

Error returns the ErrUnknownCommand error message

type ErrUnsureCommand added in v0.6.0

type ErrUnsureCommand struct {
	Msg string
}

ErrUnsureCommand is returned by the FSM when no function command was found by the classifier

func (*ErrUnsureCommand) Error added in v0.6.0

func (e *ErrUnsureCommand) Error() string

Error returns the ErrUnsureCommand error message

type FSM

type FSM struct {
	State int               `json:"state"`
	Slots map[string]string `json:"slots"`
}

FSM models a Finite State Machine

func NewFSM added in v0.5.1

func NewFSM() *FSM

NewFSM instantiates a new FSM

func (*FSM) ExecuteCmd

func (m *FSM) ExecuteCmd(command, classifiedText string, fsmDomain *Domain) (answers []query.Answer, extension string, err error)

ExecuteCmd executes a state transition in the FSM based on the function command provided and if configured will save the classified text to a slot

func (*FSM) SaveToSlot added in v0.5.1

func (m *FSM) SaveToSlot(classifiedText string, slot Slot)

SaveToSlot saves information from the user's input/question

func (*FSM) SelectStateTransition added in v0.5.1

func (m *FSM) SelectStateTransition(command string, fsmDomain *Domain) (CmdStateTuple, TransitionFunc)

SelectStateTransition based on the command provided

func (*FSM) TransitionState added in v0.5.1

func (m *FSM) TransitionState(transitionFunc TransitionFunc, defaults Defaults) (answers []query.Answer, extension string, err error)

TransitionState FSM state and return the query answers or extension to execute.

type Function

type Function struct {
	Transition Transition `yaml:"transition"`
	Command    string     `yaml:"command"`
	Slot       Slot       `yaml:"slot"`
	Extension  string     `yaml:"extension"`
	Message    []Message  `yaml:"message"`
}

Function lists the transitions available for the FSM

type Message added in v0.5.0

type Message struct {
	Text  string `yaml:"text"`
	Image string `yaml:"image"`
}

Message that is sent when a transition is executed

type Slot

type Slot struct {
	Name  string `yaml:"name"`
	Mode  string `yaml:"mode"`
	Regex string `yaml:"regex"`
}

Slot is used to save information from the user's input

type SlotTable added in v0.5.1

type SlotTable map[CmdStateTuple]Slot

SlotTable contains the mapping of state tuples to slots TODO: Document how the SlotTable works

func NewSlotTable added in v0.5.1

func NewSlotTable(functions []Function, stateTable StateTable) SlotTable

NewSlotTable initializes a new SlotTable

type StateTable added in v0.5.1

type StateTable map[string]int

StateTable contains a mapping of state names to state ids TODO: Document how the StateTable works

func NewStateTable added in v0.5.1

func NewStateTable(states []string) StateTable

NewStateTable initializes a new StateTable

type Transition

type Transition struct {
	From []string `yaml:"from"`
	Into string   `yaml:"into"`
}

Transition describes the states of the transition (from one state into another) if the functions command is executed

type TransitionFunc

type TransitionFunc func(m *FSM) (extension string, messages []Message)

TransitionFunc performs a state transition for the FSM. TODO: Document how the TransitionFunc works

func NewTransitionFunc

func NewTransitionFunc(state int, extension string, messages []Message) TransitionFunc

NewTransitionFunc generates a new transition function that will transition the FSM into the specified state and return the extension and the states defined messages

type TransitionTable added in v0.5.1

type TransitionTable map[CmdStateTuple]TransitionFunc

TransitionTable contains the mapping of state tuples to transition functions TODO: Document how the TransitionTable works

func NewTransitionTable added in v0.5.1

func NewTransitionTable(functions []Function, stateTable StateTable) TransitionTable

NewTransitionTable initializes a new TransitionTable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL