pub struct Text { /* private fields */ }Expand description
A Markov chain text model for generating random sentences
Implementations§
Source§impl Text
impl Text
Sourcepub fn new(
input_text: &str,
state_size: usize,
retain_original: bool,
well_formed: bool,
reject_reg: Option<&str>,
) -> Result<Self>
pub fn new( input_text: &str, state_size: usize, retain_original: bool, well_formed: bool, reject_reg: Option<&str>, ) -> Result<Self>
Create a new Text model from input text
§Arguments
input_text- The source text to build the model fromstate_size- Number of words in the model’s state (default: 2)retain_original- Whether to keep the original corpus for overlap checkingwell_formed- Whether to reject sentences with unmatched quotes/parenthesisreject_reg- Optional custom regex pattern for rejecting sentences
Sourcepub fn from_chain(
chain: Chain,
parsed_sentences: Option<Vec<Vec<String>>>,
retain_original: bool,
) -> Self
pub fn from_chain( chain: Chain, parsed_sentences: Option<Vec<Vec<String>>>, retain_original: bool, ) -> Self
Create a Text model from an existing chain
Sourcepub fn sentence_split(&self, text: &str) -> Vec<String>
pub fn sentence_split(&self, text: &str) -> Vec<String>
Split text into sentences
Sourcepub fn sentence_join(&self, sentences: &[String]) -> String
pub fn sentence_join(&self, sentences: &[String]) -> String
Join sentences into text
Sourcepub fn word_split(&self, sentence: &str) -> Vec<String>
pub fn word_split(&self, sentence: &str) -> Vec<String>
Split a sentence into words
Sourcepub fn test_sentence_input(&self, sentence: &str) -> bool
pub fn test_sentence_input(&self, sentence: &str) -> bool
Test if a sentence input is valid
Sourcepub fn make_sentence(
&self,
init_state: Option<&[String]>,
tries: Option<usize>,
max_overlap_ratio: Option<f64>,
max_overlap_total: Option<usize>,
test_output: Option<bool>,
max_words: Option<usize>,
min_words: Option<usize>,
) -> Option<String>
pub fn make_sentence( &self, init_state: Option<&[String]>, tries: Option<usize>, max_overlap_ratio: Option<f64>, max_overlap_total: Option<usize>, test_output: Option<bool>, max_words: Option<usize>, min_words: Option<usize>, ) -> Option<String>
Generate a random sentence
§Arguments
init_state- Optional starting state (tuple of words)tries- Maximum number of attempts (default: 10)max_overlap_ratio- Maximum overlap ratio with original text (default: 0.7)max_overlap_total- Maximum overlap total with original text (default: 15)test_output- Whether to test output for overlap (default: true)max_words- Maximum number of words in the sentencemin_words- Minimum number of words in the sentence
Sourcepub fn make_short_sentence(
&self,
max_chars: usize,
min_chars: Option<usize>,
init_state: Option<&[String]>,
tries: Option<usize>,
max_overlap_ratio: Option<f64>,
max_overlap_total: Option<usize>,
test_output: Option<bool>,
max_words: Option<usize>,
min_words: Option<usize>,
) -> Option<String>
pub fn make_short_sentence( &self, max_chars: usize, min_chars: Option<usize>, init_state: Option<&[String]>, tries: Option<usize>, max_overlap_ratio: Option<f64>, max_overlap_total: Option<usize>, test_output: Option<bool>, max_words: Option<usize>, min_words: Option<usize>, ) -> Option<String>
Generate a short sentence with a maximum character count
Sourcepub fn make_sentence_with_start(
&self,
beginning: &str,
strict: bool,
tries: Option<usize>,
max_overlap_ratio: Option<f64>,
max_overlap_total: Option<usize>,
test_output: Option<bool>,
max_words: Option<usize>,
min_words: Option<usize>,
) -> Result<String>
pub fn make_sentence_with_start( &self, beginning: &str, strict: bool, tries: Option<usize>, max_overlap_ratio: Option<f64>, max_overlap_total: Option<usize>, test_output: Option<bool>, max_words: Option<usize>, min_words: Option<usize>, ) -> Result<String>
Generate a sentence that starts with a specific string
Sourcepub fn compile_inplace(&mut self)
pub fn compile_inplace(&mut self)
Compile the model in place (returns self)
Sourcepub fn state_size(&self) -> usize
pub fn state_size(&self) -> usize
Get the state size
Sourcepub fn retain_original(&self) -> bool
pub fn retain_original(&self) -> bool
Check if the model retains original sentences
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Text
impl RefUnwindSafe for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnsafeUnpin for Text
impl UnwindSafe for Text
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