2021-10-11 09:18:28 +01:00
|
|
|
package sentiment
|
|
|
|
|
|
|
|
|
|
import (
|
2021-11-01 11:00:21 +00:00
|
|
|
"go.m3o.com/client"
|
2021-10-11 09:18:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewSentimentService(token string) *SentimentService {
|
|
|
|
|
return &SentimentService{
|
|
|
|
|
client: client.NewClient(&client.Options{
|
|
|
|
|
Token: token,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SentimentService struct {
|
|
|
|
|
client *client.Client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Analyze and score a piece of text
|
|
|
|
|
func (t *SentimentService) Analyze(request *AnalyzeRequest) (*AnalyzeResponse, error) {
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
rsp := &AnalyzeResponse{}
|
|
|
|
|
return rsp, t.client.Call("sentiment", "Analyze", request, rsp)
|
2021-12-21 13:18:29 +00:00
|
|
|
|
2021-10-11 09:18:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AnalyzeRequest struct {
|
|
|
|
|
// The language. Defaults to english.
|
|
|
|
|
Lang string `json:"lang"`
|
|
|
|
|
// The text to analyze
|
|
|
|
|
Text string `json:"text"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AnalyzeResponse struct {
|
|
|
|
|
// The score of the text {positive is 1, negative is 0}
|
|
|
|
|
Score float64 `json:"score"`
|
|
|
|
|
}
|