Documentation ¶
Overview ¶
Package intellexer provides an API client implementation for various endpoints in the Intellexer Natural Language Processing API.
Index ¶
- Constants
- type APIError
- type Client
- func (c *Client) AnalyzeSentiments(ontology Ontology, reviews []Review) (*SentimentResponse, error)
- func (c *Client) GetTopics(body io.Reader) ([]string, error)
- func (c *Client) GetTopicsFromText(body string) ([]string, error)
- func (c *Client) GetTopicsFromURL(url string) ([]string, error)
- func (c *Client) ListOntologies() ([]Ontology, error)
- func (c *Client) WithBaseURL(baseURL string) *Client
- func (c *Client) WithHTTPClient(client httpClient) *Client
- type Ontology
- type Opinion
- type Review
- type Sentence
- type Sentiment
- type SentimentResponse
Constants ¶
const ( Hotels = Ontology("hotels") Restaurants = Ontology("restaurants") Gadgets = Ontology("gadgets") )
These are all the supported ontologies for intellexer. Note that the endpoint for listing these will capitalize these, but the sentiment analysis endpoint will not. The API is case-insensitive, so for the purposes of unit testing, they will be all lowercase. It is recommended to convert to lowercase in any code expecting equality.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is an error returned by the intellexer API. You can retrieve the response object from this error. These are returned wrapped as pkg/error objects for the purpose of stack traces, but you can get the cause by calling .Cause() on those.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an intellexer API client
func (*Client) AnalyzeSentiments ¶
func (c *Client) AnalyzeSentiments(ontology Ontology, reviews []Review) (*SentimentResponse, error)
AnalyzeSentiments analyzes the reviews passed in for overall sentiment. You should assume this call will take a while. It is a network call to a machine learning-based API, and therefore could have a lot of overhead. Also, take care not to exceed the request size determined by your API level.
func (*Client) GetTopics ¶
GetTopics gets a list of topics from the article read from the body. Note that this will actually cause the remote server to read through and analyze the entire article, which will usually take a few seconds and tends to scale with the size of the article.
func (*Client) GetTopicsFromText ¶
GetTopicsFromText is a convenience function to get topics from a string. You probably want to use GetTopics instead if you already have an io.Reader.
func (*Client) GetTopicsFromURL ¶
GetTopicsFromURL gets a list of topics from the article at the given URL. See doc for "GetTopics" for performance information.
func (*Client) ListOntologies ¶
ListOntologies lists the ontologies available for analysis. This endpoint is supported almost exclusively for completeness, the intellexer API only supports three ontologies, 'Hotels', 'Restaurants', and 'Gadgets' which are exported as `Hotels`, `Restaurants` and `Gadgets`.
func (*Client) WithBaseURL ¶
WithBaseURL sets the internal base URL to hit when sending API requests. Overriding is useful for testing and development.
func (*Client) WithHTTPClient ¶
WithHTTPClient sets the internal HTTP client that should be used. Default is http.DefaultClient
type Ontology ¶
type Ontology string
Ontology is a context within which sentiment analysis evaluates reviews.
type Opinion ¶
type Opinion struct { // Children is a slice of sub-opinions that are related to / factored into // this opinion Children []Opinion `json:"children"` // F is an undocumented field F int `json:"f"` // RS is an undocumented field RS []int `json:"rs"` // Text is either the topic of this opinion or the text from the review that // it is based on. This may not always come directly from the review text. Text *string `json:"t"` // SentimentWeight is the positive or negative weight of this opinion SentimentWeight float64 `json:"w"` }
Opinion is a nested set of analyzed components of a review. It contains data about which parts of the review contributed positively and negatively.
type Review ¶
Review is the text and ID of a review that should be analyzed for sentiment.
func NewAnalyzeSentimentsRequestBody ¶
NewAnalyzeSentimentsRequestBody returns a new request body for the /analyzeSentiments endpoint, generating UUIDs for each review. It is not recommended to use this, callers are instead recommended to generate their own UUIDs so they can be cross-referenced with the results.
type Sentence ¶
type Sentence struct { // SentimentID is the ID of the sentement that this sentence comes from. SentimentID string `json:"sid"` // Text is the xml-annotated text of this sentence Text string `json:"text"` // SentimentWeight is the positive or negative weight of this sentence SentimentWeight float64 `json:"w"` }
Sentence is a sentence within the review that has been annotated with an XML- like format. Key words/phrases are enclosed in either <pos> tags or <neg> tags with attribute `w` as the sentiment weight of that word.
type Sentiment ¶
type Sentiment struct { // ID is the unique ID of this sentiment, should be what was passed in. ID string `json:"id"` // SentimentWeight is the positive or negative weight of this review. SentimentWeight float64 `json:"w"` // These fields don't seem to ever populate and are always null. Author *string `json:"author"` Datetime *string `json:"dt"` Title *string `json:"title"` }
Sentiment is an overall assessment of a review. A positive review will have a SentimentWeight above 0, and a negative one will be below 0.
type SentimentResponse ¶
type SentimentResponse struct { SentimentsCount int `json:"sentimentsCount"` Ontology Ontology `json:"ontology"` Sentences []Sentence `json:"sentences"` Opinions Opinion `json:"opinions"` Sentiments []Sentiment `json:"sentiments"` }
SentimentResponse is the response format from the AnalyzeSentiments API
Directories ¶
Path | Synopsis |
---|---|
Package main provides an example application making use of the intellexer API, and also a command-line interface for exploring the API's behavior.
|
Package main provides an example application making use of the intellexer API, and also a command-line interface for exploring the API's behavior. |
Package mocks provides utilities for testing the intellexer client.
|
Package mocks provides utilities for testing the intellexer client. |