wit

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

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

Go to latest
Published: Aug 31, 2017 License: MIT Imports: 12 Imported by: 2

README

go-wit

Build Status GoDoc

A Go library for the Wit.ai API for Natural Language Processing.

Version

0.4

Installation

go get -u github.com/christianrondeau/go-wit

Reference

Usage

package main

import (
	"github.com/christianrondeau/go-wit"
	"encoding/json"
	"log"
	"os"
)

func main() {
  // Initialize the client
	client := wit.NewClient(os.Getenv("WIT_ACCESS_TOKEN"))

  // Text processing
	result, _ := client.Message("Hello World")
	log.Println(result.Entities["intent"].value)

	// Speech processing
	request = &wit.MessageRequest{}
	request.File = "../_audio_sample/helloWorld.wav"
	request.ContentType = "audio/wav;rate=8000"
	result, _ = client.AudioMessage(request)
	log.Println(result.Entities["intent"].value)
}

## Testing

Set the `WIT_ACCESS_TOKEN` environment variable to your [Wit](https://wit.ai) Server API token

    cd go-wit
    go test

## License

[MIT](LICENSE.txt)

## Author

Original Author: Jason Goecke [@jsgoecke](https://twitter.com/jsgoecke)
Maintainer: Christian Rondeau [@christianrondeau](https://github.com/christianrondeau)

Documentation

Index

Constants

View Source
const (
	// UserAgent is the HTTP Uesr Agent sent on HTTP requests
	UserAgent = "WIT (Go net/http)"
	// APIVersion is the version of the Wit API supported
	APIVersion = "v=20170307"
)

Variables

View Source
var APIKey string

Stores the ApiKey for the Wit API

Functions

This section is empty.

Types

type AmountOfMoneyInterval

type AmountOfMoneyInterval struct {
	Unit  *string  `json:"unit"`
	Value *float64 `json:"value"`
}

type Client

type Client struct {
	APIBase string
}

Client represents a client for the Wit API (https://wit.ai/docs/api)

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new client for the Wit API

client := wit.NewClient("<ACCESS-TOKEN>")

func (*Client) AudioMessage

func (client *Client) AudioMessage(request *MessageRequest) (*MessageResponse, error)

AudioMessage requests processing of an audio message (https://wit.ai/docs/api#toc_8)

request := &MessageRequest{}
request.File = "./_audio_sample/helloWorld.wav"
request.FileContents = data
request.ContentType = "audio/wav;rate=8000"
message, err := client.AudioMessage(request)

func (*Client) CreateEntity

func (client *Client) CreateEntity(entity *Entity) (*Entity, error)

CreateEntity creates a new entity (https://wit.ai/docs/api#toc_19)

result, err := client.CreateEntity(entity)

func (*Client) CreateEntityValue

func (client *Client) CreateEntityValue(id string, entityValue *EntityValue) (*Entity, error)

CreateEntityValue creates a new entity value (https://wit.ai/docs/api#toc_25)

result, err := client.CreateEntityValue("favorite_city, entityValue)

func (*Client) CreateEntityValueExp

func (client *Client) CreateEntityValueExp(id string, value string, exp string) (*Entity, error)

CreateEntityValueExp creates a new entity value expression (https://wit.ai/docs/api#toc_25)

result, err := client.CreateEntityValueExp("favorite_city", "Barcelona", "Paella")

func (*Client) DeleteEntity

func (client *Client) DeleteEntity(id string) error

DeleteEntity deletes an entity (https://wit.ai/docs/api#toc_30)

result, err := client.DeleteEntity("favorite_city")

func (*Client) DeleteEntityValue

func (client *Client) DeleteEntityValue(id string, value string) ([]byte, error)

DeleteEntityValue deletes an entity's value (https://wit.ai/docs/api#toc_25)

result, err := client.DeleteEntityValue("favorite_city", "Paris")

func (*Client) DeleteEntityValueExp

func (client *Client) DeleteEntityValueExp(id string, value string, exp string) ([]byte, error)

DeleteEntityValueExp deletes an entity's value's expression (https://wit.ai/docs/api#toc_35)

result, err := client.DeleteEntityValueExp("favorite_city", "Paris", "")

func (*Client) Entities

func (client *Client) Entities() (*Entities, error)

Entities lists the configured entities (https://wit.ai/docs/api#toc_15)

result, err := client.Entities()

func (*Client) Entity

func (client *Client) Entity(id string) (*Entity, error)

Entity lists a single configured entity (https://wit.ai/docs/api#toc_17)

result, err := client.Entity("wit$temperature")

func (*Client) IntentShow

func (client *Client) IntentShow(intentId string) (*Intent, error)

func (*Client) Intents

func (client *Client) Intents() (*Intents, error)

Intents lists intents configured in the Wit API (https://wit.ai/docs/api#toc_13)

result, err := client.Intents()

func (*Client) Message

func (client *Client) Message(q string) (*MessageResponse, error)

Message requests processing of a text message (https://wit.ai/docs/http/20170307#get--message-link)

message, err := client.Message("Hello world")

func (*Client) UpdateEntity

func (client *Client) UpdateEntity(entity *Entity) ([]byte, error)

UpdateEntity updates and entity (https://wit.ai/docs/api#toc_22)

result, err := client.UpdateEntity(entity)

type Datetime

type Datetime struct {
	Value string  `json:"value"`
	Grain string  `json:"grain"`
	Type  *string `json:"type"`
}

type DatetimeInterval

type DatetimeInterval struct {
	From Datetime `json:"from"`
	To   Datetime `json:"to"`
}

DatetimeValue represents the datetime value portion of a Wit message

type Entities

type Entities []string

Entities represents a slice of entites when returend as an array (https://wit.ai/docs/api#toc_15)

type Entity

type Entity struct {
	Builtin bool     `json:"builtin,omitempty"`
	Doc     string   `json:"doc"`
	Exotic  bool     `json:"exotic,omitempty"`
	ID      string   `json:"id"`
	Lang    string   `json:"lang,omitempty"`
	Name    string   `json:"name,omitempty"`
	Lookups []string `json:"lookups,omitempty"`
}

Entity represents an Entity for the Wit API (https://wit.ai/docs/api#toc_15)

type EntityValue

type EntityValue struct {
	Value       string   `json:"value"`
	Metadata    string   `json:"metadata,omitempty"`
	Expressions []string `json:"expressions"`
}

EntityValue represents a Value within an Entity

type Expression

type Expression struct {
	Expression string `json:"expression"`
}

Expression respresents the expression

type HTTPParams

type HTTPParams struct {
	Verb        string
	Resource    string
	ContentType string
	Data        []byte
}

HTTPParams represents the HTTP parameters to pass along to the Wit API

type Intent

type Intent struct {
	ID          string             `json:"id"`
	Name        string             `json:"name"`
	Doc         string             `json:"doc"`
	Metadata    string             `json:"metadata"`
	Entities    []IntentEntity     `json:"entities"`
	Expressions []IntentExpression `json:"expressions"`
}

type IntentEntity

type IntentEntity struct {
	Entity
	Role string `json:"role"`
}

type IntentExpression

type IntentExpression struct {
	Body               string                   `json:"body"`
	ID                 string                   `json:"id"`
	ExpressionEntities []IntentExpressionEntity `json:"entities"`
}

type IntentExpressionEntity

type IntentExpressionEntity struct {
	Wisp  string `json:"wisp"`
	Value string `json:"value"`
	Start int64  `json:"start"`
	End   int64  `json:"end"`
}

type Intents

type Intents []Intent

type MessageEntity

type MessageEntity struct {
	Metadata   *string     `json:"metadata,omitempty"`
	Value      interface{} `json:"value,omitempty"`
	Confidence float64     `json:"confidence"`
	Body       *string     `json:"body,omitempty"`
	Start      *int64      `json:"start,omitempty"`
	End        *int64      `json:"end,omitempty"`
	Type       *string     `json:"type,omitempty"`
	Unit       *string     `json:"unit,omitempty"`
	From       interface{} `json:"from,omitempty"`
	To         interface{} `json:"to,omitempty"`
	Values     interface{} `json:"values,omitempty"`
}

MessageEntity represents the entity portion of a Wit message

type MessageRequest

type MessageRequest struct {
	File         string `json:"file,omitempty"`
	MsgID        string `json:"msg_id,omitempty"`
	Context      string `json:"context, omitempty"`
	ContentType  string `json:"contentType, omitempty"`
	FileContents []byte `json:"-"`
}

MessageRequest represents a request to process a message

type MessageResponse

type MessageResponse struct {
	MsgID    string                     `json:"msg_id"`
	Text     string                     `json:"_text"`
	Entities map[string][]MessageEntity `json:"entities"`
}

MessageResponse represents a Wit message (https://wit.ai/docs/api#toc_3)

Jump to

Keyboard shortcuts

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