fsm

package module
v0.0.0-...-5e85a13 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 7 Imported by: 0

README

fsm

Finite State Machine library, made for chatbots.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(texts []string) []string

Normalize text for FSM processing

func RegisterAction

func RegisterAction(action Action)

RegisterAction - register an action

Types

type Action

type Action struct {
	Name    string
	Handler ActionHandler
}

Action - named handler

type ActionHandler

type ActionHandler func(...string) (string, error)

ActionHandler - function pointer for this action's handler

type Call

type Call struct {
	Name string   `yaml:"fn"`
	Args []string `yaml:"args"`
}

Call - call to a handler, name of handler and args

type Class

type Class struct {
	Name   string
	Values []string
}

Class - named set of stings for classifier

type FSM

type FSM struct {
	Transitions *TransitionTable  // all transitions
	States      map[string]*State // all states
	State       *State            // current state
}

FSM - finite state machine struct

func Load

func Load(path string) *FSM

Load - makes a new finite state machine from the given config file

func New

func New(table *TransitionTable) *FSM

New - makes a new finite state machine from the given config

func (*FSM) Eval

func (f *FSM) Eval(call Call, input string) (string, error)

Eval - invoke an action with arguments

func (*FSM) Handle

func (f *FSM) Handle(input string) (string, error)

Handle - process input and transition

func (*FSM) Transition

func (f *FSM) Transition(newState string, input string) (string, error)

Transition - transition to new state

type State

type State struct {
	Name       string
	Classes    []Class
	Classifier *bayesian.Classifier
	// contains filtered or unexported fields
}

State - single state

type Transition

type Transition struct {
	Source string `yaml:"src"`
	Dest   string `yaml:"dst"`

	Auto bool     `yaml:"auto"`
	On   []string `yaml:"on"`
	Do   []Call   `yaml:"do"`
	Once []Call   `yaml:"once"`
}

Transition - single entry in the transition table

type TransitionTable

type TransitionTable struct {
	Imports     []string     `yaml:"imports"`
	Transitions []Transition `yaml:"transitions"`
}

TransitionTable - main structure of FSM

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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