1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-29 21:47:44 +02:00
Files
go-micro/services/sentiment/sentiment.go

38 lines
758 B
Go
Raw Normal View History

package sentiment
import (
2021-11-01 11:00:21 +00:00
"go.m3o.com/client"
)
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
rsp := &AnalyzeResponse{}
return rsp, t.client.Call("sentiment", "Analyze", request, rsp)
2021-12-21 13:18:29 +00: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"`
}