Documentation ¶
Index ¶
- Constants
- type Answer
- type BaseDomain
- type CmdStateTuple
- type Defaults
- type Domain
- type ErrUnknownCommand
- type ErrUnsureCommand
- type Extension
- type FSM
- func (m *FSM) ExecuteCmd(command, classifiedText string, fsmDomain *Domain) (answers []query.Answer, extension *Extension, err error)
- func (m *FSM) SaveToSlot(classifiedText string, slot Slot)
- func (m *FSM) SelectStateTransition(command string, fsmDomain *Domain) (CmdStateTuple, TransitionFunc)
- func (m *FSM) TransitionState(transitionFunc TransitionFunc, defaults Defaults) (answers []query.Answer, extension *Extension, err error)
- type Slot
- type SlotTable
- type StateTable
- type Transition
- type TransitionFunc
- type TransitionTable
Constants ¶
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 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 ¶
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 FSM ¶
FSM models a Finite State Machine
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
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
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 ¶
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