know

package module
v0.0.0-...-bed1a63 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2014 License: MIT Imports: 10 Imported by: 1

README

know

API Documentation MIT License

Package know queries different knowledge providers and parses their result. Partially supported are currently Google and Wolfram Alpha.

Installation

go get github.com/xconstruct/know

Example

answers, errs := know.Ask("What is the capital of germany?")

// Get first answer
ans, ok := <-answers
if !ok {
	fmt.Println("No answer found!")
	for err := range errs {
		fmt.Println(err)
	}
	return
}
fmt.Println(ans.Question, "is", ans.Answer)
// Output:
// Germany, Capital is Berlin

Documentation

Overview

Package know queries different knowledge providers and parses their result. Partially supported are currently Google and Wolfram Alpha.

Index

Constants

This section is empty.

Variables

View Source
var (
	Google  = NewGoogleProvider()
	Wolfram = NewWolframProvider()
)

Functions

func Ask

func Ask(question string) (<-chan *Answer, <-chan error)

Ask asks all currently supported providers the same question and returns their answers on a channel. The channels are closed when all providers are finished. Empty answer and error channels signify a successful query, but no provider could answer that question.

func AskProviders

func AskProviders(question string, providers []Provider) (<-chan *Answer, <-chan error)

AskProviders asks all specified providers the same question and returns their answers and errors on a channel. The channels are closed when all providers are finished. Empty answer and error channels signify a successful query, but no provider could answer that question.

func RegisterProvider

func RegisterProvider(p Provider)

RegisterProvider registers a new provider which is used in the default set of providers.

Types

type Answer

type Answer struct {
	Query    string
	Question string
	Answer   string
	Media    []*Media
	Provider string
}

Answer represents the collective result of a provider query.

func NewAnswer

func NewAnswer() *Answer

NewAnswer constructs a new empty answer.

type GoogleProvider

type GoogleProvider struct {
	Debugf func(format string, v ...interface{})
}

func NewGoogleProvider

func NewGoogleProvider() *GoogleProvider

func (*GoogleProvider) Ask

func (p *GoogleProvider) Ask(question string) (*Answer, error)

func (*GoogleProvider) Name

func (p *GoogleProvider) Name() string

type Media

type Media struct {
	Type string
	Url  string
}

Media represents a media object in the answer.

type Provider

type Provider interface {
	Name() string
	Ask(question string) (*Answer, error)
}

Provider is a knowledge provider that can answer questions.

type WolframProvider

type WolframProvider struct {
	ApiKey string
}

func NewWolframProvider

func NewWolframProvider() *WolframProvider

func (*WolframProvider) Ask

func (p *WolframProvider) Ask(question string) (*Answer, error)

func (*WolframProvider) Name

func (p *WolframProvider) Name() string

func (*WolframProvider) SetApiKey

func (p *WolframProvider) SetApiKey(key string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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