language

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: 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 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 Confused

func Confused() string

Confused returns a randomized response signalling that Abot is confused or could not understand the user's request.

func Contains

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

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

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) sql.NullInt64

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

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

TODO this should return an *int64 to maintain consistency with the Extract API.

func ExtractCurrency

func ExtractCurrency(s string) sql.NullInt64

ExtractCurrency returns a pointer to a string to allow a user a simple check to see if currency text was found. If the response is nil, no currency was found. This API design also maintains consistency when we want to extract and return a struct (which should be returned as a pointer).

func ExtractYesNo

func ExtractYesNo(s string) sql.NullBool

ExtractYesNo determines whether a string (typically a sentence sent by a user to Abot) contains a Yes or No response. This is useful for plugins to determine a user's answer to a Yes/No question.

TODO should be converted to return a *bool for consistency with the rest of the Extract API.

func Foods

func Foods() []string

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

TODO expand.

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 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 seperator.

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 Vehicles

func Vehicles() []string

Vehicles 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