natural

package
v0.0.0-...-0dfd57a Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package natural contains a multitude of natural language parsers.

Index

Constants

View Source
const (
	ThisAlgorithmBecomingSkynetCost = 999999999
)

Variables

View Source
var DefaultPhraseResponses = map[string]string{
	"compliment":       "thanks",
	"thanks":           "acknowledgement",
	"greeting/initial": "greeting/reply",
	"greeting/reply":   "greeting/reply",
	"wake":             "greeting/reply",
	"farewell":         "farewell",
	"success":          "compliment",
	"affirmative":      "compliment",
}
View Source
var DefaultRules = SentenceRuleSet{
	"ping":                               "ping",
	"associate [sentence] with [action]": "natural/learn",
	"parse [text]":                       "natural/parse",

	"record that [text]": "event/new",
	"#[_action]":         "tagged",
	"#[_action] [text]":  "tagged",

	"remind me in [duration] to [text]": "schedule",
}

Functions

func FormatMessage

func FormatMessage(msg *sarif.Message)

func FormatSimple

func FormatSimple(msg sarif.Message) string

func ParseSimple

func ParseSimple(text string) (sarif.Message, bool)

func ParseValue

func ParseValue(v string) interface{}

func SplitQuoted

func SplitQuoted(s string, sep string) ([]string, bool)

func SplitWords

func SplitWords(s string) []string

func TrimQuotes

func TrimQuotes(s string) string

Types

type Context

type Context struct {
	Text          string
	ExpectedReply string
	Sender        string
	Recipient     string
}

type Intent

type Intent struct {
	Intent string  `json:"intent"`
	Type   string  `json:"type"`
	Weight float64 `json:"weight"`

	Message   sarif.Message `json:"msg"`
	ExtraInfo interface{}   `json:"extra_info"`
}

func (Intent) String

func (p Intent) String() string

type ParseResult

type ParseResult struct {
	Text      string      `json:"text"`
	Intents   []*Intent   `json:"intents"`
	ExtraInfo interface{} `json:"extra_info"`
}

func (*ParseResult) Merge

func (r *ParseResult) Merge(other *ParseResult, weight float64)

func (ParseResult) String

func (r ParseResult) String() string

type Phrasebook

type Phrasebook struct {
	Rand    *rand.Rand
	Phrases map[string][]string
}

func NewPhrasebook

func NewPhrasebook() *Phrasebook

func (*Phrasebook) Answer

func (b *Phrasebook) Answer(phrase string) string

func (*Phrasebook) Get

func (b *Phrasebook) Get(context string) string

func (*Phrasebook) GetReverse

func (b *Phrasebook) GetReverse(phrase string) string

type RegularParser

type RegularParser struct {
	// contains filtered or unexported fields
}

func NewRegularParser

func NewRegularParser() *RegularParser

func (*RegularParser) Learn

func (p *RegularParser) Learn(rule, action string) error

func (*RegularParser) Load

func (p *RegularParser) Load(s SentenceRuleSet) error

func (*RegularParser) Parse

func (p *RegularParser) Parse(s string) (sarif.Message, bool)

func (*RegularParser) Rules

func (p *RegularParser) Rules() SentenceRuleSet

type SentenceRule

type SentenceRule struct {
	Rule     string
	Action   string
	Regexp   *regexp.Regexp
	Priority int
}

func CompileSentenceRule

func CompileSentenceRule(s, action string) (r *SentenceRule, err error)

func (*SentenceRule) Parse

func (r *SentenceRule) Parse(s string) (sarif.Message, bool)

type SentenceRuleSet

type SentenceRuleSet map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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