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" "path/filepath"
"github.com/hamcha/clessy/tg" "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() { func initoroscopo() {
counter := 0 counter := 0
corpus := "" orogen = gomarkov.NewChain()
filepath.Walk(*oropath, func(path string, info os.FileInfo, err error) error { filepath.Walk(*oropath, func(path string, info os.FileInfo, err error) error {
if info.IsDir() { if info.IsDir() {
return nil return nil
@ -27,24 +27,27 @@ func initoroscopo() {
return err return err
} }
corpus += string(data) orogen.Update(string(data))
counter++ counter++
return nil return nil
}) })
orogen = mctext.New()
orogen.Parse(strings.NewReader(corpus))
log.Printf("[oroscopo] Loaded corpus from %d files\n", counter) log.Printf("[oroscopo] Loaded corpus from %d files\n", counter)
} }
func oroscopo(broker *tg.Broker, update tg.APIMessage) { func oroscopo(broker *tg.Broker, update tg.APIMessage) {
if isCommand(update, "oroscopo") { if isCommand(update, "oroscopo") {
txt := "" var err error
var txt string
tries := 0 tries := 0
for tries < 10 { 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, '.') idx := strings.LastIndexByte(txt, '.')
if idx < 10 { if idx < 10 {
tries++ tries++