diff options
-rw-r--r-- | bot/bot.go | 56 |
1 files changed, 25 insertions, 31 deletions
@@ -1,4 +1,7 @@ -// Port of jim-bot from C to go. +// Port of jim-bot from C to Go with minor wordlist additions. +// +// Original C source is available here: +// <https://pmdn.org/pocket-jim/> package bot import ( @@ -304,7 +307,7 @@ var adjectives = []string { } // noun word list -// (note: added "A.I." for 2025) +// (note: added "A.I." and "blockchain" for 2025) var nouns = []string { "action items", "alignments", @@ -414,6 +417,12 @@ var delims = []string { ", and ", } +// Phrase which contains the following: +// +// 1. Adverb (optional). +// 2. Verb (required). +// 3. Adjectives (optional, 0-4) +// 4. Noun (required). type Phrase struct { HasAdverb bool // does this phrase have an adverb? Adverb int // word position in adverbs @@ -422,6 +431,17 @@ type Phrase struct { Noun int // word position in nouns } +// Create new phrase. +func newPhrase() Phrase { + return Phrase { + HasAdverb: (rand.IntN(2) == 1), // has adverb? + Adverb: rand.IntN(len(adverbs)), // pick random adverb + Verb: rand.IntN(len(verbs)), // pick random verb + Adjectives: rand.Perm(len(adjectives))[:(rand.IntN(5))], // pick adjectives + Noun: rand.IntN(len(nouns)), // noun + } +} + // convert phrase to string func (p Phrase) String() string { var b strings.Builder @@ -466,44 +486,18 @@ func (p Phrase) String() string { return b.String() } +// Sentence consisting of [1,4] phrases delimited by join clauses. type Sentence struct { Phrases []Phrase // phrases Joins []int // phrase joins } -// get 0-5 unique adjectives -func uniqueAdjectives() []int { - num := rand.IntN(5) // number of adjectives - - lut := make(map[int]bool) - for len(lut) < num { - n := rand.IntN(len(adjectives)) - if !lut[n] { - lut[n] = true - } - } - - // build result - r := make([]int, 0, num) - for n := range(lut) { - r = append(r, n) - } - - // return result - return r -} - // Create sentence func NewSentence() Sentence { + // create phrases phrases := make([]Phrase, 1 + rand.IntN(3)) for i := range(len(phrases)) { - // adverb - phrases[i].HasAdverb = (rand.IntN(2) == 1) - phrases[i].Adverb = rand.IntN(len(adverbs)) - - phrases[i].Verb = rand.IntN(len(verbs)) // verb - phrases[i].Adjectives = uniqueAdjectives() // adjectives - phrases[i].Noun = rand.IntN(len(nouns)) // noun + phrases[i] = newPhrase() } // return sentence |