Browse Source

added progress bar on generating Markov states

master
arnaucode 7 years ago
parent
commit
13e26f1c71
2 changed files with 17 additions and 3 deletions
  1. +4
    -3
      main.go
  2. +13
    -0
      markov.go

+ 4
- 3
main.go

@ -9,7 +9,7 @@ import (
"strings"
)
func readText(path string) (string, error) {
func readTxt(path string) (string, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
//Do something
@ -38,10 +38,11 @@ func main() {
fmt.Println("incorrect entry, need a positive number")
}
text, _ := readText("text.txt")
text, _ := readTxt("text.txt")
fmt.Println("generating text")
fmt.Println("generating markov chains")
states := markov.train(text)
fmt.Println("generating text")
generatedText := markov.generateText(states, firstWord, count)
fmt.Println("")
fmt.Println(generatedText)

+ 13
- 0
markov.go

@ -18,6 +18,17 @@ type State struct {
var markov Markov
func printLoading(n int, total int) {
var bar []string
tantPerFourty := int((float64(n) / float64(total)) * 40)
tantPerCent := int((float64(n) / float64(total)) * 100)
for i := 0; i < tantPerFourty; i++ {
bar = append(bar, "█")
}
progressBar := strings.Join(bar, "")
fmt.Printf("\r " + progressBar + " - " + strconv.Itoa(tantPerCent) + "%")
}
func addWordToStates(states []State, word string) ([]State, int) {
iState := -1
for i := 0; i < len(states); i++ {
@ -48,6 +59,8 @@ func calcMarkovStates(words []string) []State {
if iState < len(words) {
states[iState].NextStates, _ = addWordToStates(states[iState].NextStates, words[i+1])
}
printLoading(i, len(words))
}
//count prob

Loading…
Cancel
Save