semantic_commands/
input.rs

1fn normalize(s: &str) -> String {
2	s.to_lowercase()
3		.replace(|c: char| !c.is_alphanumeric() && !c.is_whitespace(), " ")
4		.split_whitespace() //	avoid usage tabs, new lines etc
5		.collect::<Vec<_>>()
6		.join(" ")
7		.trim()
8		.to_string()
9}
10
11#[derive(Default, Debug)]
12pub struct Input {
13	pub text: String,
14	pub embedding: Option<Vec<f32>>,
15}
16
17impl Input {
18	/// Create a new input from raw text
19	///
20	/// The text will be normalized automatically
21	pub fn new(text: &str) -> Self {
22		Self {
23			text: normalize(text),
24			embedding: None,
25		}
26	}
27}
28
29#[cfg(test)]
30mod tests {
31	use super::*;
32
33	#[test]
34	fn test_normalize() {
35		let input = "Hello, World! This is a Test.";
36		let expected = "hello world this is a test";
37		assert_eq!(normalize(input), expected);
38	}
39}