forked from an/flokati
if no answer can be found, build sentence on empty string
This commit is contained in:
parent
5207b0fde0
commit
78056ade35
|
@ -222,7 +222,11 @@ func (c *MarkovChain) Generate(n int, in string) string {
|
||||||
for attempt := 0; attempt < 10; attempt++ {
|
for attempt := 0; attempt < 10; attempt++ {
|
||||||
p = make(MarkovPrefix, c.prefixLen)
|
p = make(MarkovPrefix, c.prefixLen)
|
||||||
inWords := strings.Split(in, " ")
|
inWords := strings.Split(in, " ")
|
||||||
start = inWords[rand.Intn(len(inWords))]
|
if attempt < 9 {
|
||||||
|
start = inWords[rand.Intn(len(inWords))]
|
||||||
|
} else {
|
||||||
|
start = ""
|
||||||
|
}
|
||||||
p.Shift(start)
|
p.Shift(start)
|
||||||
xlog.Debug("Looking for answer on [%s]", start)
|
xlog.Debug("Looking for answer on [%s]", start)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
|
@ -242,13 +246,7 @@ func (c *MarkovChain) Generate(n int, in string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
start = strings.Trim(start, " ")
|
start = strings.Trim(start, " ")
|
||||||
if len(words) == 0 {
|
return start + " " + strings.Join(words, " ")
|
||||||
xlog.Debug("No answer found")
|
|
||||||
return start + " ... pfrrrz"
|
|
||||||
} else {
|
|
||||||
xlog.Debug("Found words: [%s]", strings.Join(words, " "))
|
|
||||||
return start + " " + strings.Join(words, " ")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the chain to a file
|
// Save the chain to a file
|
||||||
|
|
Loading…
Reference in New Issue