mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-21 22:45:06 +00:00
Commit from m3o/m3o action
This commit is contained in:
35
go/sentiment/sentiment.go
Executable file
35
go/sentiment/sentiment.go
Executable file
@@ -0,0 +1,35 @@
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user