change how no-num /sentance works

serve
Avril 4 years ago
parent 1d482029f3
commit ca16c97629
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "markov"
version = "0.6.3"
version = "0.6.4"
description = "Generate string of text from Markov chain fed by stdin"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"

@ -178,7 +178,7 @@ impl Filter
output
}
pub fn filter_str<'a, T: AsRef<str>+'a>(&'a self, string: &'a T) -> FilterStr<'a>
pub fn filter_str<'a, T: AsRef<str>+'a +?Sized>(&'a self, string: &'a T) -> FilterStr<'a>
{
FilterStr(string.as_ref(), self, OnceCell::new())
}

@ -68,7 +68,7 @@ impl Sentance
}
/// Create a new iterator over sentances from this string.
pub fn new_iter<'a>(from: &'a (impl AsRef<str> +'a + ?Sized)) -> impl Iterator<Item = &'a Self>
pub fn new_iter<'a>(from: &'a (impl AsRef<str> +'a + ?Sized)) -> impl Iterator<Item = &'a Self> + Clone
{
let from = from.as_ref();
from.split_inclusive(is_sentance_boundary)

@ -17,10 +17,18 @@ pub async fn body(state: State, num: Option<usize>, mut output: mpsc::Sender<Str
debug!("Taking {:?} from {:?}" ,num, string);
let filter = state.outbound_filter();
for sen in sanitise::Sentance::new_iter(&string).take(num.unwrap_or(1))
if let Some(num) = num {
for sen in sanitise::Sentance::new_iter(&string).take(num)
{
output.send(filter.filter_owned(sen.to_owned())).await.map_err(|e| gen::GenBodyError(e.0))?;
}
} else {
output.send(filter.filter_owned(match sanitise::Sentance::new_iter(&string)
.max_by_key(|x| x.len()) {
Some(x) => x,
#[cold] None => return Ok(()),
}.to_owned())).await.map_err(|e| gen::GenBodyError(e.0))?;
}
Ok(())
}

Loading…
Cancel
Save