fuck that mctext thing

This commit is contained in:
Hamcha 2017-08-07 15:39:48 +02:00
parent 8c09558922
commit c97576b635

View file

@ -9,14 +9,14 @@ import (
"path/filepath"
"github.com/hamcha/clessy/tg"
"github.com/zgiber/mctext"
gomarkov "github.com/simon-weber/gomarkov"
)
var orogen *mctext.MChain
var orogen *gomarkov.Chain
func initoroscopo() {
counter := 0
corpus := ""
orogen = gomarkov.NewChain()
filepath.Walk(*oropath, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
@ -27,24 +27,27 @@ func initoroscopo() {
return err
}
corpus += string(data)
orogen.Update(string(data))
counter++
return nil
})
orogen = mctext.New()
orogen.Parse(strings.NewReader(corpus))
log.Printf("[oroscopo] Loaded corpus from %d files\n", counter)
}
func oroscopo(broker *tg.Broker, update tg.APIMessage) {
if isCommand(update, "oroscopo") {
txt := ""
var err error
var txt string
tries := 0
for tries < 10 {
txt = orogen.Generate("", 100)
txt, err = orogen.Respond("", 20, 100)
if err != nil {
txt = err.Error()
tries++
continue
}
idx := strings.LastIndexByte(txt, '.')
if idx < 10 {
tries++