repurpose split-sentance to make sense; add feed-sentance for old functionality

feed
Avril 4 years ago
parent 633b4351c2
commit 8996b0bb7b
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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 <flanchan@cumallover.me>"]
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

@ -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);

Loading…
Cancel
Save