feat: dictation segmentation on blank lines
This commit is contained in:
+20
-1
@@ -1 +1,20 @@
|
|||||||
// implemented in a later task
|
/// Split a dictation into Befund segments on Markdown paragraph
|
||||||
|
/// breaks (one or more blank lines). Trims each segment; drops empties.
|
||||||
|
pub fn split_segments(dictation: &str) -> Vec<String> {
|
||||||
|
let mut segments = Vec::new();
|
||||||
|
let mut current: Vec<&str> = Vec::new();
|
||||||
|
for line in dictation.lines() {
|
||||||
|
if line.trim().is_empty() {
|
||||||
|
if !current.is_empty() {
|
||||||
|
segments.push(current.join("\n").trim().to_string());
|
||||||
|
current.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !current.is_empty() {
|
||||||
|
segments.push(current.join("\n").trim().to_string());
|
||||||
|
}
|
||||||
|
segments.into_iter().filter(|s| !s.is_empty()).collect()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
use alpha_id::segment::split_segments;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn splits_on_blank_lines() {
|
||||||
|
let d = "Befund eins\nmit Zeile zwei\n\nBefund zwei\n\n\nBefund drei\n";
|
||||||
|
let segs = split_segments(d);
|
||||||
|
assert_eq!(segs, vec![
|
||||||
|
"Befund eins\nmit Zeile zwei".to_string(),
|
||||||
|
"Befund zwei".to_string(),
|
||||||
|
"Befund drei".to_string(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn single_segment_when_no_blank_line() {
|
||||||
|
assert_eq!(split_segments("nur ein Befund"), vec!["nur ein Befund".to_string()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_input_yields_no_segments() {
|
||||||
|
assert!(split_segments(" \n\n").is_empty());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user