# Packages
No description provided by the author
# README
GopherText 🐹
GopherText is a lightweight and efficient Go library for generating random text using Markov chains. Perfect for text generation tasks, chatbots, or just having fun with procedural text!
Features
- Configurable Markov Order: Choose the number of words to use as context (e.g., bigrams, trigrams).
- Simple API: Easy-to-use methods for training and generating text.
- Efficient: Built with Go's performance and simplicity in mind.
- Extensible: Add your own preprocessing or tokenization logic.
Installation
To use GopherText in your Go project, run:
go get github.com/jasonlovesdoggo/gophertext
Usage
Basic Example
package main
import (
"fmt"
"github.com/jasonlovesdoggo/gophertext"
)
func main() {
// Initialize a Markov model with order 2 (bigrams)
mm := gophertext.NewMarkovModel(2)
// Train the model with sample text
text := `The quick brown fox jumps over the lazy dog.
The lazy dog barked at the quick fox.
The fox ran away from the dog.`
mm.BuildModel(text)
// Generate 50 words of random text
result, err := mm.Generate(50)
if err != nil {
panic(err)
}
fmt.Println("Generated text:")
fmt.Println(result)
}
Output
Generated text:
The quick brown fox jumps over the lazy dog barked at the quick fox ran away from the dog. The lazy dog barked at the quick brown fox jumps over the lazy dog.
API Reference
NewMarkovModel(order int) *MarkovModel
Creates a new Markov model with the specified order (number of words to use as context).
BuildModel(text string)
Trains the model on the provided text.
Generate(numWords int) (string, error)
Generates random text with the specified number of words. Returns an error if the model hasn't been trained.
Contributing
Contributions are welcome! Here’s how you can help:
- Report Bugs: Open an issue describing the bug.
- Suggest Features: Share your ideas for new features.
- Submit Pull Requests: Implement fixes or improvements.
Please follow the Go Code Review Comments for style guidelines.
License
GopherText is licensed under the MIT License. See LICENSE for details.
Acknowledgments
- Inspired by Markov chain text generation techniques.
- Built with ❤️ and Go.
Star the Repo ⭐
If you find GopherText useful, please give it a star on GitHub!