-
Notifications
You must be signed in to change notification settings - Fork 0
/
markov_tester.go
53 lines (46 loc) · 1.16 KB
/
markov_tester.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"bufio"
"strings"
"os"
"github.com/SheepTester/baby-moofy/markov"
"github.com/SheepTester/baby-moofy/utils"
)
var path string = "./data/frequencies.json"
var order int = 3
func main() {
fmt.Println("Hello! Let me remember how to speak...")
markovFreqs, err := markov.LoadMarkov(path)
if err != nil {
fmt.Println("Couldn't load frequencies JSON file:", err)
return
}
fmt.Println("Okay, I'm ready.")
lastWords := []string{"/"}
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("> ")
for scanner.Scan() {
words := utils.Simplify(scanner.Text())
if len(words) == 0 {
continue
}
total := append(append(lastWords, words...), "/")
if len(total) < order {
lastWords = total
fmt.Println("Insufficient context:", strings.Join(lastWords, " "))
} else {
total = total[len(total)-order:]
gen := markov.GenerateLoud(markovFreqs, strings.Join(total, " "))
fmt.Println(gen)
words = utils.Simplify(gen)
if len(words) > 0 {
lastWords = append(append(total, words...), "/")
}
}
fmt.Print("> ")
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Problem reading the epic STIN:", err)
}
}