fsm

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// StateInitial is the first state the FSM enters upon
	// initialization of a new conversation and when ending
	// an existing conversation
	StateInitial = 0
	// StateAny allows transitioning from any state
	StateAny = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer added in v0.7.0

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

Answer that is sent when a transition is executed

type BaseDomain added in v0.5.0

type BaseDomain struct {
	StateTable      StateTable `json:"state_table"`
	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(transitions []Transition, 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 Extension

type Extension struct {
	Server string `yam:"server"`
	Name   string `yam:"name"`
}

Extension is the specific extension server and name to execute by the transition

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 *Extension, 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 *Extension, err error)

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

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(transitions []Transition, 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(transitions []Transition) StateTable

NewStateTable initializes a new StateTable

type Transition

type Transition struct {
	From      []string  `yaml:"from"`
	Into      string    `yaml:"into"`
	Command   string    `yaml:"command"`
	Slot      Slot      `yaml:"slot"`
	Extension Extension `yaml:"extension"`
	Answers   []Answer  `yaml:"answers"`
}

Transition lists the transitions available for the FSM 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 *Extension, answers []Answer)

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

func NewTransitionFunc

func NewTransitionFunc(state int, extension *Extension, answers []Answer) 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(transitions []Transition, 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