core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package core handles the internal logic of Abot. It's kept separate from the shared/ libraries which plugins may depend upon. This package should rarely (if ever) be used externally outside of Abot's core.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCommand = errors.New("invalid command")

ErrInvalidCommand denotes that a user-inputted command could not be processed.

View Source
var ErrMissingPlugin = errors.New("missing plugin")

ErrMissingPlugin denotes that Abot could find neither a plugin with matching triggers for a user's message nor any prior plugin used. This is most commonly seen on first run if the user's message doesn't initially trigger a plugin.

Functions

func BootDependencies

func BootDependencies(avaRPCAddr string) error

BootDependencies executes all binaries listed in "plugins.json". each dependencies is passed the rpc address of the ava core. it is expected that each dependency respond with there own rpc address when registering themselves with the ava core.

func BootRPCServer

func BootRPCServer() (addr string, err error)

BootRPCServer starts the rpc for Abot core in a go routine and returns the server address

func BuildOffensiveMap

func BuildOffensiveMap() (map[string]struct{}, error)

BuildOffensiveMap creates a map of offensive terms for which Abot will refuse to respond. This helps ensure that users are somewhat respectful to Abot and her human trainers, since sentences caught by the OffensiveMap are rejected before any human ever sees them.

func CallPlugin

func CallPlugin(pw *plugin.Wrapper, m *dt.Msg, followup bool) (pluginReply string,
	err error)

CallPlugin sends a plugin the user's preprocessed message. The followup bool dictates whether this is the first consecutive time the user has sent that plugin a message, or if the user is engaged in a conversation with the plugin. This difference enables plugins to respond differently--like reset state-- when messaged for the first time in each new conversation.

func CompileAssets

func CompileAssets() error

CompileAssets compresses and merges assets from Abot core and all plugins on boot. In development, this step is repeated on each server HTTP request prior to serving any assets.

func DB

func DB() *sqlx.DB

func GetPlugin

func GetPlugin(db *sqlx.DB, m *dt.Msg) (*plugin.Wrapper, string, bool, error)

GetPlugin attempts to find a plugin and route for the given msg input if none can be found, it checks the database for the last route used and gets the plugin for that. If there is no previously used plugin, we return ErrMissingPlugin. The bool value return indicates whether this plugin is different from the last plugin used by the user.

func JSONError

func JSONError(err error) error

JSONError builds a simple JSON message from an error type in the format of { "Msg": err.Error() }. This ensures that any client expecting a JSON error message (e.g. Abot's web front-end) receives one.

func NewMsg

func NewMsg(u *dt.User, cmd string) *dt.Msg

NewMsg builds a message struct with Tokens, Stems, and a Structured Input.

func NewServer

func NewServer() (*echo.Echo, error)

NewServer connects to the database and boots all plugins before returning a server connection, database connection, and map of offensive words.

func Offensive

func Offensive() map[string]struct{}

func Preprocess

func Preprocess(c *echo.Context) (*dt.Msg, error)

Preprocess converts a user input into a Msg that's been persisted to the database

func ProcessText

func ProcessText(c *echo.Context) (ret string, uid uint64, err error)

ProcessText is Abot's core logic. This function processes a user's message, routes it to the correct plugin, and handles edge cases like offensive language before returning a response to the user. Any user-presentable error is returned in the string. Errors returned from this function are not for the user, so they are handled by Abot explicitly on this function's return (logging, notifying admins, etc.).

func RespondWithNicety

func RespondWithNicety(in *dt.Msg) (responseNecessary bool, response string)

RespondWithNicety replies to niceties that humans use, but Abot can ignore. Words like "Thank you" are not necessary for a robot, but it's important Abot respond correctly nonetheless. The returned bool specifies whether a response is necessary, and the returned string is the response, if any.

func RespondWithOffense

func RespondWithOffense(off map[string]struct{}, in *dt.Msg) string

RespondWithOffense is a one-off function to respond to rude user language by refusing to process the command.

Types

type Abot

type Abot int

Abot is defined to use in RPC communication

func (*Abot) RegisterPlugin

func (t *Abot) RegisterPlugin(p *plugin.Plugin, reply *string) error

RegisterPlugin enables Abot to notify plugins when specific StructuredInput is encountered matching triggers set in the plugins themselves. Note that plugins will only listen when ALL criteria are met and that there's no support currently for duplicate routes (e.g. "find_restaurant" leading to either one of two plugins).

type Classifier

type Classifier map[string]struct{}

Classifier is a set of common english word stems unique among their Structured Input Types. This enables extremely fast constant-time O(1) lookups of stems to their SITs with high accuracy and no training requirements. It consumes just a few MB in memory.

func BuildClassifier

func BuildClassifier() (Classifier, error)

BuildClassifier prepares the Named Entity Recognizer (NER) to find Commands and Objects using a simple dictionary lookup. This has the benefit of high speed--constant time, O(1)--with insignificant memory use and high accuracy given false positives (marking something as both a Command and an Object when it's really acting as an Object) are OK. Utlimately this should be a first pass, and any double-marked words should be passed through something like an n-gram Bayesian filter to determine the correct part of speech within its context in the sentence.

func NER

func NER() Classifier

func (Classifier) ClassifyTokens

func (c Classifier) ClassifyTokens(tokens []string) *nlp.StructuredInput

ClassifyTokens builds a StructuredInput from a tokenized sentence.

Directories

Path Synopsis
Package template builds commonly used emails filled in with custom information.
Package template builds commonly used emails filled in with custom information.
Package websocket manages websocket connections and notifications for Abot clients.
Package websocket manages websocket connections and notifications for Abot clients.

Jump to

Keyboard shortcuts

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