markov
continuous-integration/drone/push Build is passing Details

This commit is contained in:
an 2019-08-24 14:39:55 +02:00
parent a517f0d638
commit 75b18d7107
1 changed files with 5 additions and 4 deletions

View File

@ -115,8 +115,9 @@ func markovParseText(text string) string {
text = strings.Replace(text, ">", ">", -1)
text = strings.Replace(text, "&", "&", -1)
text = strings.Replace(text, ",", " ", -1)
return strings.ToLower(text)
reg := regexp.MustCompile("[^a-zA-Z0-9 ]+")
delText := reg.ReplaceAllString(text, "")
return strings.ToLower(delText)
}
// Prefix is a Markov chain prefix of one or more words.
@ -212,9 +213,9 @@ func (c *MarkovChain) Generate(n int, in string) string {
}
next := choices[rand.Intn(len(choices))]
words = append(words, next)
if strings.HasSuffix(next, ".") || strings.HasSuffix(next, "!") || strings.HasSuffix(next, "?") {
/*if strings.HasSuffix(next, ".") || strings.HasSuffix(next, "!") || strings.HasSuffix(next, "?") {
break
}
}*/
p.Shift(next)
}
if len(words) > 0 {