https://github.com/ix/rust-markov-text
Markov text library for Rust.
https://github.com/ix/rust-markov-text
Last synced: about 1 year ago
JSON representation
Markov text library for Rust.
- Host: GitHub
- URL: https://github.com/ix/rust-markov-text
- Owner: ix
- License: mit
- Created: 2016-06-01T00:15:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-29T22:33:38.000Z (almost 10 years ago)
- Last Synced: 2025-02-12T14:28:05.622Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 1.23 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# markov-text
A crate for Markov text generation.
Example:
```rust
extern crate markov_text;
use markov_text::{Dictionary, Sentence};
use std::fs::File;
use std::io::prelude::*;
fn main() {
let mut markov = Dictionary::new();
let mut file = File::open("example").expect("Couldn't open `example` file.");
let mut buf = String::new();
file.read_to_string(&mut buf).expect("Failed to read the file!");
markov.parse(Sentence::from(&*buf)).unwrap();
let prefix = markov.rand_prefix().expect("Failed to get a prefix!"); {
println!("{}", markov.generate(&prefix, 60).unwrap());
}
}
```
Or, once you've created a dictionary and parsed some text to it, you can generate from your own "prefix", that is, two words (though this may be configurable in the future) as so:
```rust
let prefix = ("the".into(), "game".into()); {
println!("{}", markov.generate(&prefix, 60).unwrap());
}
```