forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/brianvoe/gofakeit/v6/word_comment.go

119 lines
2.0 KiB
Go
Raw Normal View History

2024-04-26 19:30:35 +00:00
package gofakeit
import (
"math/rand"
"strings"
)
// Comment will generate a random statement or remark expressing an opinion, observation, or reaction
2024-04-26 19:30:35 +00:00
func Comment() string { return comment(globalFaker.Rand) }
// Comment will generate a random statement or remark expressing an opinion, observation, or reaction
2024-04-26 19:30:35 +00:00
func (f *Faker) Comment() string { return comment(f.Rand) }
func comment(r *rand.Rand) string {
2024-04-26 19:30:35 +00:00
structures := [][]string{
2024-04-26 19:30:35 +00:00
{"interjection", "adjective", "noun", "verb", "adverb"},
2024-04-26 19:30:35 +00:00
{"noun", "verb", "preposition", "determiner", "adjective", "noun"},
2024-04-26 19:30:35 +00:00
{"noun", "verb", "adverb"},
2024-04-26 19:30:35 +00:00
{"adjective", "noun", "verb"},
2024-04-26 19:30:35 +00:00
{"noun", "verb", "preposition", "noun"},
}
// Randomly select a structure
2024-04-26 19:30:35 +00:00
structure := structures[number(r, 0, len(structures)-1)]
// Build the sentence
2024-04-26 19:30:35 +00:00
var commentParts []string
2024-04-26 19:30:35 +00:00
for _, wordType := range structure {
2024-04-26 19:30:35 +00:00
switch wordType {
2024-04-26 19:30:35 +00:00
case "noun":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, noun(r))
2024-04-26 19:30:35 +00:00
case "verb":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, verb(r))
2024-04-26 19:30:35 +00:00
case "adjective":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, adjective(r))
2024-04-26 19:30:35 +00:00
case "adverb":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, adverb(r))
2024-04-26 19:30:35 +00:00
case "interjection":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, interjection(r))
2024-04-26 19:30:35 +00:00
case "preposition":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, preposition(r))
2024-04-26 19:30:35 +00:00
case "determiner":
2024-04-26 19:30:35 +00:00
commentParts = append(commentParts, nounDeterminer(r))
2024-04-26 19:30:35 +00:00
default:
2024-04-26 19:30:35 +00:00
// Should never hit
2024-04-26 19:30:35 +00:00
panic("Invalid word type")
2024-04-26 19:30:35 +00:00
}
2024-04-26 19:30:35 +00:00
}
// Combine the words into a sentence
2024-04-26 19:30:35 +00:00
sentence := strings.Join(commentParts, " ")
// Capitalize the first letter
2024-04-26 19:30:35 +00:00
sentence = title(sentence)
// Add a period to the end of the sentence
2024-04-26 19:30:35 +00:00
sentence = sentence + "."
return sentence
2024-04-26 19:30:35 +00:00
}
func addWordCommentLookup() {
2024-04-26 19:30:35 +00:00
AddFuncLookup("comment", Info{
Display: "Comment",
Category: "word",
2024-04-26 19:30:35 +00:00
Description: "Statement or remark expressing an opinion, observation, or reaction",
Example: "wow",
Output: "string",
2024-04-26 19:30:35 +00:00
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
2024-04-26 19:30:35 +00:00
return interjection(r), nil
2024-04-26 19:30:35 +00:00
},
})
2024-04-26 19:30:35 +00:00
}