Skip to main content

markovify_rs/
lib.rs

1//! # markovify-rs
2//!
3//! A Rust implementation of a Markov chain text generator, inspired by [markovify](https://github.com/jsvine/markovify).
4//!
5//! Markovify-rs is a simple, extensible Markov chain generator. Its primary use is for building
6//! Markov models of large corpora of text and generating random sentences from that.
7//!
8//! ## Basic Usage
9//!
10//! ```rust
11//! use markovify_rs::Text;
12//!
13//! // Build the model
14//! let text = "Hello world. This is a test. The quick brown fox jumps.";
15//! let model = Text::new(text, 2, true, true, None).unwrap();
16//!
17//! // Generate a random sentence
18//! if let Some(sentence) = model.make_sentence(None, None, None, None, None, None, None) {
19//!     println!("{}", sentence);
20//! }
21//!
22//! // Generate a short sentence
23//! if let Some(sentence) = model.make_short_sentence(100, None, None, None, None, None, None, None, None) {
24//!     println!("Short: {}", sentence);
25//! }
26//! ```
27//!
28//! ## Features
29//!
30//! - Configurable state size
31//! - Sentence generation with overlap detection
32//! - Model compilation for faster generation
33//! - Model combination with weights
34//! - JSON export/import for persistence
35//! - Newline-delimited text support
36
37pub mod chain;
38pub mod errors;
39pub mod splitters;
40pub mod text;
41pub mod utils;
42
43pub use chain::{Chain, BEGIN, END};
44pub use errors::{MarkovError, Result};
45pub use splitters::split_into_sentences;
46pub use text::{NewlineText, Text};
47pub use utils::{combine_chains, combine_models, combine_texts, CombinedResult, ModelRef};
48
49/// Library version
50pub const VERSION: &str = env!("CARGO_PKG_VERSION");