1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/services/sentiment/sentiment.go
Asim Aslam 4ae2528cbe
add m3o services (#2301)
* add m3o services

* update readme
2021-10-11 09:18:28 +01:00

36 lines
767 B
Go
Executable File

package sentiment
import (
"github.com/m3o/m3o-go/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) {
rsp := &AnalyzeResponse{}
return rsp, t.client.Call("sentiment", "Analyze", request, rsp)
}
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"`
}