-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (56 loc) · 1.26 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main(){
cmdReader := bufio.NewReader(os.Stdin)
options :=`
1 - Generate text
2 - Exit
`
for {
fmt.Println(options)
option, _ := cmdReader.ReadString('\n')
option = strings.TrimSpace(option)
switch option{
case "1":
content, err := ReadText("example.pdf")
if err != nil {
fmt.Printf("Error occurred with readText: %v\n", err)
}
chain := Train(content)
start(chain)
//printChain(chain)
break
case "2":
return
break
default:
fmt.Println("Wrong option")
}
}
}
func start(chain []MarkovChain){
cmdReader := bufio.NewReader(os.Stdin)
fmt.Print("\nEnter word from which will start the generation - ")
word, _ := cmdReader.ReadString('\n')
word = strings.TrimSpace(word)
fmt.Print("Enter the count of word in the chain - ")
answer, _ := cmdReader.ReadString('\n')
answer = strings.TrimSpace(answer)
count, _ := strconv.Atoi(answer)
text := GenerateMarkovText(chain, word, count)
fmt.Println("Result - ", text)
}
func printChain(chain []MarkovChain){
for i := 0; i < len(chain); i++ {
fmt.Println(i+1," - ",chain[i].value, " prob - ", chain[i].prob)
if chain[i].nextChain != nil {
printChain(chain[i].nextChain)
}
}
}