markov: fixed severe bug in Shift()
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
327ce86ccd
commit
a517f0d638
|
@ -129,9 +129,13 @@ func (p MarkovPrefix) String() string {
|
||||||
|
|
||||||
// Shift removes the first word from the Prefix and appends the given word.
|
// Shift removes the first word from the Prefix and appends the given word.
|
||||||
func (p MarkovPrefix) Shift(word string) {
|
func (p MarkovPrefix) Shift(word string) {
|
||||||
|
if len(p) < *markovPrefixLen {
|
||||||
|
p = append(p, word)
|
||||||
|
} else {
|
||||||
copy(p, p[1:])
|
copy(p, p[1:])
|
||||||
p[len(p)-1] = word
|
p[len(p)-1] = word
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MarkovChain contains a map ("chain") of prefixes to a list of suffixes.
|
// MarkovChain contains a map ("chain") of prefixes to a list of suffixes.
|
||||||
// A prefix is a string of prefixLen words joined with spaces.
|
// A prefix is a string of prefixLen words joined with spaces.
|
||||||
|
|
Loading…
Reference in New Issue