textapi

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 10 Imported by: 8

README

About

This is the Go client library for AYLIEN's APIs. If you haven't already done so, you will need to sign up.

Installation

To install, simply use go get:

$ go get github.com/AYLIEN/aylien_textapi_go

See the Developers Guide for additional documentation.

Example

package main

import (
	"fmt"
	textapi "github.com/AYLIEN/aylien_textapi_go"
)

func main() {
	auth := textapi.Auth{"YourApplicationId", "YourApplicationKey"}
	client, err := textapi.NewClient(auth, true)
	if err != nil {
		panic(err)
	}
	params := &textapi.SentimentParams{Text: "John is a very good football player!"}
	sentiment, err := client.Sentiment(params)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", sentiment)
}

Support

support@aylien.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aspect

type Aspect struct {
	Aspect             string  `json:"aspect"`
	AspectConfidence   float32 `json:"aspect_confidence"`
	Polarity           string  `json:"polarity"`
	PolarityConfidence float32 `json:"polarity_confidence"`
}

Aspect is the JSON description of an aspect.

type AspectBasedSentimentParams

type AspectBasedSentimentParams struct {
	// Either URL or Text is required.
	Text string
	URL  string

	// The domain that document belongs to.
	Domain string
}

AspectBasedSentimentParams is the set of parameters that defines a document whose sentiment needs analysis.

type AspectBasedSentimentResponse

type AspectBasedSentimentResponse struct {
	Text      string   `json:"text"`
	Domain    string   `json:"domain"`
	Aspects   []Aspect `json:"aspects"`
	Sentences []struct {
		Text               string   `json:"text"`
		Polarity           string   `json:"polarity"`
		PolarityConfidence float32  `json:"polarity_confidence"`
		Aspects            []Aspect `json:"aspects"`
	} `json:"sentences"`
}

AspectBasedSentimentResponse is the JSON description of aspect based sentiment analysis.

type Auth

type Auth struct {
	// ApplicationID and ApplicationKey identify the client using Text API.
	// These fields are always required
	ApplicationID  string
	ApplicationKey string
}

An Auth is an authentication token that will be used to authenticate client.

type Category

type Category struct {
	// IPTC SubjectCode
	Code       string  `json:"code"`
	Label      string  `json:"label"`
	Confidence float32 `json:"confidence"`
}

A Category is the JSON description of a classification category.

type ClassifyByTaxonomyParams

type ClassifyByTaxonomyParams struct {
	// Either URL or Text is required.
	URL  string
	Text string

	// Valid languages are en, de, fr, es, it, pt and auto.
	// Default is en.
	Language string

	// Valid taxonomies are iab-qag and iptc-subjectcode.
	Taxonomy string
}

A ClassifyByTaxonomyParams is the set of parameters that defines a document whose needs to be classified according to a taxonomy.

type ClassifyByTaxonomyResponse

type ClassifyByTaxonomyResponse struct {
	Text       string `json:"text"`
	Language   string `json:"language"`
	Taxonomy   string `json:"taxonomy"`
	Categories []struct {
		Id        string  `json:"id"`
		Label     string  `json:"label"`
		Score     float32 `json:"score"`
		Confident bool    `json:"confident"`
		Links     []struct {
			Link string `json:"link"`
			Rel  string `json:"rel"`
		} `json:"links"`
	} `json:"categories"`
}

A ClassifyByTaxonomyResponse is the JSON description of classification by taxonomy response.

type ClassifyParams

type ClassifyParams struct {
	// Either URL or Text is required.
	URL  string
	Text string

	// Valid languages are en, de, fr, es, it, pt and auto.
	// Default is en.
	Language string
}

ClassifyParams is the set of parameters that defines a document whose classification needs to be calculated.

type ClassifyResponse

type ClassifyResponse struct {
	Text       string     `json:"text"`
	Language   string     `json:"language"`
	Categories []Category `json:"categories"`
}

A ClassifyResponse is the JSON description of classify response.

type Client

type Client struct {
	RateLimits *RateLimits
	// contains filtered or unexported fields
}

A Client can make calls to the Text API.

func NewClient

func NewClient(auth Auth, useHTTPS bool) (*Client, error)

NewClient returns a new client using the given auth information. To use HTTPS, pas useHttps = true.

func (*Client) AspectBasedSentiment

func (c *Client) AspectBasedSentiment(params *AspectBasedSentimentParams) (*AspectBasedSentimentResponse, error)

AspectBasedSentiment given a review for a product or service, analyzes the sentiment of the review towards each of the aspects of the product or review that are mentioned in it.

func (*Client) Classify

func (c *Client) Classify(params *ClassifyParams) (*ClassifyResponse, error)

Classify classifies the document defined by the given params information.

func (*Client) ClassifyByTaxonomy

func (c *Client) ClassifyByTaxonomy(params *ClassifyByTaxonomyParams) (*ClassifyByTaxonomyResponse, error)

ClassifyByTaxonomy classifies the document defined by the given params information according to the specified taxonomy.

func (*Client) Combined

func (c *Client) Combined(params *CombinedParams) (*CombinedResponse, error)

func (*Client) Concepts

func (c *Client) Concepts(params *ConceptsParams) (*ConceptsResponse, error)

Concepts extracts concepts mentioned in the document defined by the given params information.

func (*Client) Elsa added in v0.6.0

func (c *Client) Elsa(params *ElsaParams) (*ElsaResponse, error)

Elsa extracts entities mentioned in the document defined by the given params information.

func (*Client) Entities

func (c *Client) Entities(params *EntitiesParams) (*EntitiesResponse, error)

Entities extracts entities mentioned in the document defined by the given params information.

func (*Client) Extract

func (c *Client) Extract(params *ExtractParams) (*ExtractResponse, error)

Extract extracts information from the web page defined by the given params information.

func (*Client) Hashtags

func (c *Client) Hashtags(params *HashtagsParams) (*HashtagsResponse, error)

Hashtags calculates best hashtags describing the document defined by the given params information.

func (*Client) ImageTags

func (c *Client) ImageTags(params *ImageTagsParams) (*ImageTagsResponse, error)

TagImage tags image defined by the given params information.

func (*Client) Language

func (c *Client) Language(params *LanguageParams) (*LanguageResponse, error)

Language calculates the language in which the document defined by the given params information is written in.

func (*Client) Sentiment

func (c *Client) Sentiment(params *SentimentParams) (*SentimentResponse, error)

Sentiment detects the sentiment of the document defined by the given params information. It detects the sentiment in terms of polarity (positive, negative or neutral). And in terms of subjectivity (subjective or objective).

func (*Client) Summarize

func (c *Client) Summarize(params *SummarizeParams) (*SummarizeResponse, error)

Summarize summarizes the document defined by the given params information.

type CombinedParams

type CombinedParams struct {
	URL       string
	Text      string
	Endpoints []string
}

type CombinedResponse

type CombinedResponse struct {
	Text            string
	Article         ExtractResponse
	Summary         SummarizeResponse
	Concepts        ConceptsResponse
	Entities        EntitiesResponse
	Hashtags        HashtagsResponse
	Language        LanguageResponse
	Sentiment       SentimentResponse
	Classifications ClassifyResponse
}

func (*CombinedResponse) UnmarshalJSON

func (c *CombinedResponse) UnmarshalJSON(data []byte) error

type Concept

type Concept struct {
	SurfaceForms []SurfaceForm `json:"surfaceForms"`
	Types        []string      `json:"types"`
	Support      int           `json:"support"`
}

A Concept is the JSON description of a concept in document.

type ConceptsParams

type ConceptsParams struct {
	// Either URL or Text is required.
	URL  string
	Text string

	// Valid languages are en, de, fr, es, it, pt and auto.
	// Default is en.
	Language string
}

ConceptsParams is the set of parameters that defines a document whose concepts needs to be extracted.

type ConceptsResponse

type ConceptsResponse struct {
	Text     string             `json:"text"`
	Language string             `json:"language"`
	Concepts map[string]Concept `json:"concepts"`
}

A ConceptsResponse is the JSON description of concept extraction response.

type DateTime

type DateTime struct {
	time.Time
}

DateTime embeds time.Time and acts as an alias for custom unmarshalling.

func (*DateTime) UnmarshalJSON

func (t *DateTime) UnmarshalJSON(buf []byte) error

Custom unmarshaller for time.Time which discards errors and will set the time to zero value in case parsing failed. Using time.Time.IsZero() is advised.

type ElsaParams added in v0.6.0

type ElsaParams struct {
	// Either URL or Text is required.
	URL  string
	Text string
}

ElsaParams is the set of parameters that defines a document whose entities needs to be extracted.

type ElsaResponse added in v0.6.0

type ElsaResponse struct {
	Text     string   `json:"text"`
	Entities []Entity `json:"entities"`
}

ElsaResponse is the JSON description of the elsa response.

type EntitiesParams

type EntitiesParams struct {
	// Either URL or Text is required.
	URL  string
	Text string
}

EntitiesParams is the set of parameters that defines a document whose entities needs to be extracted.

type EntitiesResponse

type EntitiesResponse struct {
	Text     string              `json:"text"`
	Entities map[string][]string `json:"entities"`
}

A EntitiesResponse is the JSON description of entities extraction response.

type Entity added in v0.6.0

type Entity struct {
	Mentions         []Mention `json:"mentions"`
	OverallSentiment Sentiment `json:"overall_sentiment"`
	Type             string    `json:"type"`
	Links            []Link    `json:"links"`
}

Entity is the JSON description of an entity in response.

type Error

type Error struct {
	Message string `json:"error"`
}

An Error is the JSON response whenever an error occurs.

type ExtractParams

type ExtractParams struct {
	// Either URL or HTML is required.
	URL  string
	HTML string // Raw HTML of web page

	// Whether to extract the best image of the article.
	BestImage bool
}

ExtractParams is the set of parameters that defines a web page whose data needs to be extracted.

type ExtractResponse

type ExtractResponse struct {
	Title       string   `json:"title"`
	Article     string   `json:"article"`
	Image       string   `json:"image"`
	Author      string   `json:"author"`
	PublishDate DateTime `json:"publishDate"`
	Videos      []string `json:"videos"`
	Feeds       []string `json:"feeds"`
	Tags        []string `json:"tags"`
}

ExtractResponse is the JSON description of extract response.

type HashtagsParams

type HashtagsParams struct {
	// Either URL or Text is required.
	URL  string
	Text string

	// Valid languages are en, de, fr, es, it, pt and auto.
	// Default is en.
	Language string
}

HashtagsParams is the set of parameters that defines a document whose hashtags need to be calculated.

type HashtagsResponse

type HashtagsResponse struct {
	Text     string   `json:"text"`
	Language string   `json:"language"`
	Hashtags []string `json:"hashtags"`
}

HashtagsResponse is the JSON description of a hashtags in a document.

type ImageTag

type ImageTag struct {
	Tag        string  `json:"tag"`
	Confidence float32 `json:"confidence"`
}

ImageTag is the JSON description of a pair of tag and confidence

type ImageTagsParams

type ImageTagsParams struct {
	URL string
}

ImageTagsParams defines the image whose tags needs to be calculated.

type ImageTagsResponse

type ImageTagsResponse struct {
	Image string     `json:"string"`
	Tags  []ImageTag `json:"tags"`
}

ImageTagsResponse is the JSON description of tag image response.

type LanguageParams

type LanguageParams struct {
	// Either URL or Text is required.
	URL  string
	Text string
}

LanguageParams is the set of parameters that defines a document whose language needs to be calculated.

type LanguageResponse

type LanguageResponse struct {
	Text       string  `json:"text"`
	Language   string  `json:"lang"`
	Confidence float32 `json:"confidence"`
}

LanguageResponse is the JSON description of language response.

type Link struct {
	URI        string   `json:"uri"`
	Provider   string   `json:"provider"`
	Types      []string `json:"types"`
	Confidence float64  `json:"confidence"`
}

Link is the JSON description of a Link entity in the response.

type Mention added in v0.6.0

type Mention struct {
	Offset     int       `json:"offset"`
	Confidence float64   `json:"confidence"`
	Text       string    `json:"text"`
	Sentiment  Sentiment `json:sentiment`
}

Mention is the JSON description of an entity mention in the response.

type RateLimits

type RateLimits struct {
	Limit     int
	Remaining int
	Reset     int
}

A RateLimits is the HTTP X-RateLimit-* headers of last response.

type Sentiment added in v0.6.0

type Sentiment struct {
	Polarity   string  `json:"polarity"`
	Confidence float64 `json:"confidence"`
}

Sentiment is the JSON description of sentiment values in the response

type SentimentParams

type SentimentParams struct {
	// Either URL or Text is required.
	Text string
	URL  string

	// Default is en.
	Language string

	// The analyze mode.
	// Valid option are tweet suitable for short text (default).
	// And document which is more suitable for longer bodies of text.
	Mode string
}

SentimentParams is the set of parameters that defines a document whose sentiment needs analysis.

type SentimentResponse

type SentimentResponse struct {
	Text                   string  `json:"text"`
	Polarity               string  `json:"polarity"`
	PolarityConfidence     float32 `json:"polarity_confidence"`
	Subjectivity           string  `json:"subjectivity"`
	SubjectivityConfidence float32 `json:"subjectivity_confidence"`
}

SentimentResponse is the JSON description of sentiment analysis.

type SummarizeParams

type SummarizeParams struct {
	// Either URL or a pair of Title and Text is required.
	URL   string
	Text  string
	Title string

	// Summarize mode
	// Valid options are default, and short.
	// short mode produces relatively shorter sentences.
	Mode string

	// Quantity of sentences in default mode.
	// Not applicable to short mode.
	NumberOfSentences     int
	PercentageOfSentences int
}

SummarizeParams is the set of parameters that defines a document whose needs to be summarized.

type SummarizeResponse

type SummarizeResponse struct {
	Text      string   `json:"text"`
	Sentences []string `json:"sentences"`
}

SummarizeResponse is the JSON description of summarize response.

type SurfaceForm

type SurfaceForm struct {
	String string  `json:"string"`
	Score  float32 `json:"score"`
	Offset int     `json:"offset"`
}

A SurfaceForm is the JSON description of a concept's surface form.

Jump to

Keyboard shortcuts

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