make sentiment subscribe to posts to enrich

This commit is contained in:
Asim Aslam
2021-03-01 14:26:04 +00:00
parent e205a485b0
commit 8b80c2da2b
6 changed files with 372 additions and 14 deletions

24
sentiment/model/model.go Normal file
View File

@@ -0,0 +1,24 @@
package model
import (
"github.com/cdipaolo/sentiment"
"github.com/micro/micro/v3/service/logger"
)
var (
model *sentiment.Models
)
func init() {
// load sentiment analysis tool
md, err := sentiment.Restore()
if err != nil {
logger.Fatal(err)
}
model = &md
}
func Analyze(text string) float64 {
an := model.SentimentAnalysis(text, sentiment.English)
return float64(an.Score)
}