pub struct MarkovModel {
pub n: usize,
pub transitions: HashMap<Vec<String>, Vec<(String, u32)>>,
pub tagged_transitions: HashMap<String, HashMap<Vec<String>, Vec<(String, u32)>>>,
}Expand description
A trained Markov model storing n-gram probability tables.
Fields§
§n: usizeN-gram depth (e.g., 2 for bigrams, 3 for trigrams).
transitions: HashMap<Vec<String>, Vec<(String, u32)>>Transition table: n-gram prefix → [(next_token, count)].
tagged_transitions: HashMap<String, HashMap<Vec<String>, Vec<(String, u32)>>>Tag-specific transition tables.
Implementations§
Source§impl MarkovModel
impl MarkovModel
Sourcepub fn generate(
&self,
rng: &mut StdRng,
tag: Option<&str>,
min_words: usize,
max_words: usize,
) -> Result<String, MarkovError>
pub fn generate( &self, rng: &mut StdRng, tag: Option<&str>, min_words: usize, max_words: usize, ) -> Result<String, MarkovError>
Generate text from this model.
Starts from a sentence-start state, walks the chain selecting next tokens by weighted probability, and stops at a sentence boundary within the word count range.
Trait Implementations§
Source§impl Clone for MarkovModel
impl Clone for MarkovModel
Source§fn clone(&self) -> MarkovModel
fn clone(&self) -> MarkovModel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MarkovModel
impl Debug for MarkovModel
Source§impl Default for MarkovModel
impl Default for MarkovModel
Source§fn default() -> MarkovModel
fn default() -> MarkovModel
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for MarkovModel
impl<'de> Deserialize<'de> for MarkovModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for MarkovModel
impl RefUnwindSafe for MarkovModel
impl Send for MarkovModel
impl Sync for MarkovModel
impl Unpin for MarkovModel
impl UnsafeUnpin for MarkovModel
impl UnwindSafe for MarkovModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more