|
|
|
@ -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<usize> = 2..; //TODO: Add to config somehow
|
|
|
|
@ -8,7 +9,7 @@ const FEED_BOUNDS: std::ops::RangeFrom<usize> = 2..; //TODO: Add to config someh
|
|
|
|
|
pub fn feed(chain: &mut Chain<String>, what: impl AsRef<str>, bounds: impl std::ops::RangeBounds<usize>)
|
|
|
|
|
{
|
|
|
|
|
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::<Vec<_>>());
|
|
|
|
@ -22,10 +23,17 @@ pub fn feed(chain: &mut Chain<String>, what: impl AsRef<str>, 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::<Vec<_>>();
|
|
|
|
|
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::<Vec<_>>();
|
|
|
|
|
} 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);
|
|
|
|
|