mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 03:05:14 +00:00
make sentiment subscribe to posts to enrich
This commit is contained in:
24
sentiment/model/model.go
Normal file
24
sentiment/model/model.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user