language

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package language makes it easier to build plugins and natural-sounding responses. This package does the following four things:

  1. Provides easy-to-use helpers for returning commonly used, randomized text such as greetings.
  2. Normalizes varied user responses like "yup" or "nah" into something to be more easily used by plugins.
  3. Consolidates triggers by categories (e.g. automotive brands) if commonly used across plugins.
  4. Summarizes text using the custom rule-based algorithm found in summarize.go.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("couldn't extract requested type from string")

ErrNotFound is thrown when the requested type cannot be found in the string

View Source
var Prepositions = map[string]struct{}{
	"aboard":      struct{}{},
	"about":       struct{}{},
	"above":       struct{}{},
	"across":      struct{}{},
	"after":       struct{}{},
	"against":     struct{}{},
	"along":       struct{}{},
	"amid":        struct{}{},
	"among":       struct{}{},
	"anti":        struct{}{},
	"around":      struct{}{},
	"as":          struct{}{},
	"at":          struct{}{},
	"before":      struct{}{},
	"behind":      struct{}{},
	"below":       struct{}{},
	"beneath":     struct{}{},
	"beside":      struct{}{},
	"besides":     struct{}{},
	"between":     struct{}{},
	"beyond":      struct{}{},
	"but":         struct{}{},
	"by":          struct{}{},
	"concerning":  struct{}{},
	"considering": struct{}{},
	"despite":     struct{}{},
	"down":        struct{}{},
	"during":      struct{}{},
	"except":      struct{}{},
	"excepting":   struct{}{},
	"excluding":   struct{}{},
	"following":   struct{}{},
	"for":         struct{}{},
	"from":        struct{}{},
	"in":          struct{}{},
	"inside":      struct{}{},
	"into":        struct{}{},
	"like":        struct{}{},
	"minus":       struct{}{},
	"near":        struct{}{},
	"of":          struct{}{},
	"off":         struct{}{},
	"on":          struct{}{},
	"onto":        struct{}{},
	"opposite":    struct{}{},
	"outside":     struct{}{},
	"over":        struct{}{},
	"past":        struct{}{},
	"per":         struct{}{},
	"plus":        struct{}{},
	"regarding":   struct{}{},
	"round":       struct{}{},
	"save":        struct{}{},
	"since":       struct{}{},
	"than":        struct{}{},
	"through":     struct{}{},
	"to":          struct{}{},
	"toward":      struct{}{},
	"towards":     struct{}{},
	"under":       struct{}{},
	"underneath":  struct{}{},
	"unlike":      struct{}{},
	"until":       struct{}{},
	"up":          struct{}{},
	"upon":        struct{}{},
	"versus":      struct{}{},
	"via":         struct{}{},
	"with":        struct{}{},
	"within":      struct{}{},
	"without":     struct{}{},
}

Prepositions contains the most commonly used prepositions.

View Source
var StopWords = []string{
	"a",
	"an",
	"the",
}

StopWords are articles that can be ignored by Abot.

Functions

func Alcohol

func Alcohol() []string

Alcohol is a collection of alcohol related words useful in a plugin's object trigger.

func AutomotiveBrands

func AutomotiveBrands() []string

AutomotiveBrands returns a list of automobile manufacturers useful in a plugin's object triggers.

func Broken

func Broken() []string

Broken returns a slice of words related to something breaking, which is useful in a plugin's command trigger.

func Contains

func Contains(wordList []string, s string) bool

Contains determines whether a slice of strings contains a specific word.

func Desserts added in v0.2.0

func Desserts() []string

Desserts returns a []string of dessert types useful in a plugin's object triggers

func ExtractAddress

func ExtractAddress(db *sqlx.DB, u *dt.User, s string) (*dt.Address, bool, error)

ExtractAddress will return an address from a user's message, whether it's a labeled address (e.g. "home", "office"), or a full U.S. address (e.g. 100 Penn St., CA 90000)

func ExtractCities

func ExtractCities(db *sqlx.DB, in *dt.Msg) ([]dt.City, error)

ExtractCities efficiently from a user's message.

func ExtractCount

func ExtractCount(s string) (int64, error)

ExtractCount returns a number from a user's message, useful in situations like:

Ava>  How many would you like to buy?
User> Order 5

func ExtractCurrency

func ExtractCurrency(s string) (int64, error)

ExtractCurrency returns an int64 if a currency is found, and throws an error if one isn't.

func ExtractYesNo

func ExtractYesNo(s string) (bool, error)

ExtractYesNo determines whether a string contains a Yes or No response. This is useful for plugins to determine a user's answer to a Yes/No question.

func Foods

func Foods() []string

Foods returns a list of foods useful in a plugin's object triggers.

func Greeting

func Greeting(r *rand.Rand, name string) string

Greeting returns a randomized greeting.

func Join

func Join(ss ...[]string) []string

Join concatenates triggers together, like Recommend() and Broken(), ensuring no duplicates exist

func NiceMeetingYou

func NiceMeetingYou() string

NiceMeetingYou is used to greet the user and request signup during an onboarding process.

func No

func No(s string) bool

No determines if a specific word is a "No" response. For example, "nah" returns true.

func Positive

func Positive() string

Positive returns a randomized positive response to a user message.

func Purchase

func Purchase() []string

Purchase returns a slice of words related to purchasing something, which is useful in a plugin's command trigger.

func QuestionLocation

func QuestionLocation(loc string) string

QuestionLocation returns a randomized question asking a user where they are.

func Recommend

func Recommend() []string

Recommend returns a slice of words related to recommending a product, which is useful in a plugin's command trigger.

func RemoveStopWords

func RemoveStopWords(ss []string) []string

RemoveStopWords finds and removes stopwords from a slice of strings.

func Repair

func Repair() []string

Repair returns a slice of words related to repairing something, which is useful in a plugin's command trigger.

func Restaurants added in v0.2.0

func Restaurants() []string

Restaurants returns a []string of restaurant types useful in a plugin's object triggers

func SliceToString

func SliceToString(ss []string, andor string) string

SliceToString converts a slice of strings into a natural-language list with appropriately placed commas and a custom and/or separator.

func SuggestedPlace

func SuggestedPlace(s string) string

SuggestedPlace returns a randomized place suggestion useful for recommending restaurants, businesses, etc.

func SuggestedProduct

func SuggestedProduct(s string, num uint) string

SuggestedProduct returns natural language, randomized text for a product suggestion.

func Transportation added in v0.2.0

func Transportation() []string

Transportation returns a list of vehicle types useful in a plugin's object triggers.

func Welcome

func Welcome() string

Welcome returns a randomized "you're welcome" response to a user message.

func Yes

func Yes(s string) bool

Yes determines if a specific word is a positive "Yes" response. For example, "yeah" returns true.

Types

This section is empty.

Jump to

Keyboard shortcuts

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