use serde::Serialize;
#[derive(Serialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum CorpusKind {
Csv,
Text,
}
pub struct Situation {
pub tokens: Vec<String>,
pub display: Vec<String>,
pub numbers: Vec<(String, f64)>,
pub beliefs: Vec<(String, f32)>,
}
impl Situation {
pub fn new(tokens: Vec<String>, display: Vec<String>) -> Situation {
Situation { tokens, display, numbers: Vec::new(), beliefs: Vec::new() }
}
}
pub trait Projector {
fn columns(&self) -> Vec<String>;
fn kind(&self) -> CorpusKind;
fn source(&self) -> String;
fn project(self: Box<Self>, sink: &mut dyn FnMut(Situation)) -> std::io::Result<()>;
}
pub fn slug(s: &str) -> String {
let t = s.trim().to_lowercase();
let mut out = String::with_capacity(t.len());
let mut prev_dash = false;
for ch in t.chars() {
if ch.is_whitespace() || ch == '/' {
if !prev_dash && !out.is_empty() {
out.push('-');
prev_dash = true;
}
} else {
out.push(ch);
prev_dash = false;
}
}
while out.ends_with('-') {
out.pop();
}
out
}