diff --git a/Cargo.toml b/Cargo.toml index dc5b8b3..16f4d08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "markov" -version = "0.7.3" +version = "0.7.4" description = "Generate string of text from Markov chain fed by stdin" authors = ["Avril "] edition = "2018" @@ -20,6 +20,9 @@ split-newlines = [] # Feed each sentance seperately with default /get api, instead of just each line / whole body # Maybe better without `split-newlines`? # Kinda experimental +feed-sentance = [] + +# Split input by sentances as well as words. split-sentance = [] # Always aggregate incoming buffer instead of streaming them diff --git a/src/feed.rs b/src/feed.rs index 2ac1031..c998e1b 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -1,5 +1,6 @@ //! Feeding the chain use super::*; +#[cfg(any(feature="feed-sentance", feature="split-sentance"))] use sanitise::Sentance; const FEED_BOUNDS: std::ops::RangeFrom = 2..; //TODO: Add to config somehow @@ -8,7 +9,7 @@ const FEED_BOUNDS: std::ops::RangeFrom = 2..; //TODO: Add to config someh pub fn feed(chain: &mut Chain, what: impl AsRef, bounds: impl std::ops::RangeBounds) { cfg_if! { - if #[cfg(feature="split-sentance")] { + if #[cfg(feature="feed-sentance")] { let map = Sentance::new_iter(&what) //get each sentance in string .map(|what| what.words() .map(|s| s.to_owned()).collect::>()); @@ -22,10 +23,17 @@ pub fn feed(chain: &mut Chain, what: impl AsRef, bounds: impl std:: } } } else { - let map = Sentance::new_iter(&what) //get each sentance in string - .map(|what| what.words()) - .flatten() // add all into one buffer - .map(|s| s.to_owned()).collect::>(); + cfg_if!{ + if #[cfg(feature="split-sentance")] { + let map = Sentance::new_iter(&what) //get each sentance in string + .map(|what| what.words()) + .flatten() // add all into one buffer + .map(|s| s.to_owned()).collect::>(); + } else { + let map: Vec<_> = sanitise::Word::new_iter(what.as_ref()).map(ToOwned::to_owned) + .collect(); + } + } debug_assert!(!bounds.contains(&0), "Cannot allow 0 size feeds"); if bounds.contains(&map.len()) { chain.feed(map);