Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jelni/markov-chain
A simple Markov chain Rust implementation I made to better understand this data structure.
https://github.com/jelni/markov-chain
markov-chain
Last synced: 8 days ago
JSON representation
A simple Markov chain Rust implementation I made to better understand this data structure.
- Host: GitHub
- URL: https://github.com/jelni/markov-chain
- Owner: jelni
- License: lgpl-3.0
- Created: 2023-05-22T22:25:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-14T20:49:46.000Z (5 months ago)
- Last Synced: 2024-12-07T13:42:31.210Z (16 days ago)
- Topics: markov-chain
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# markov-chain
A simple [Markov chain](https://wikipedia.org/wiki/Markov_chain) Rust
implementation I made to better understand this data structure.Any order (HashMap's key length) can be used. This decides how many words are
taken into account when generating text. More will result in better generation
results, but also requires more training input.It allows saving and restoring the state from any format that
[Serde](https://crates.io/crates/serde)) supports.## Example
```rs
fn main() {
let mut chain = MarkovChain::new(2);chain.train("lorem ipsum dolor sit amet");
// smart ai bot 🤯
chain.generate_text(16); // lorem ipsum dolor sit ametchain.save(&mut BufWriter::new(File::create("model.dat").unwrap())).unwrap();
let chain = MarkovChain::load(BufReader::new(File::open("model.dat").unwrap())).unwrap();
println!("loaded {} entries", chain.len()); // loaded 3 entries
}
```