diff --git a/src/segment.rs b/src/segment.rs index 8cd36fd..892fd7d 100644 --- a/src/segment.rs +++ b/src/segment.rs @@ -1,20 +1,13 @@ -/// 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 { - 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() +/// Split the caller-extracted phrase list into retrieval units: one +/// non-empty (trimmed) input line = one unit. Blank/whitespace-only +/// lines are skipped. Rev 2026-05-18 (spec §1a): input is extracted +/// diagnostic phrases, not a blank-line-segmented dictation. Name and +/// signature kept; a "segment" now denotes one extracted phrase. +pub fn split_segments(phrases: &str) -> Vec { + phrases + .lines() + .map(|l| l.trim()) + .filter(|l| !l.is_empty()) + .map(|l| l.to_string()) + .collect() } diff --git a/tests/segment_tests.rs b/tests/segment_tests.rs index 564f8c6..bf9a61b 100644 --- a/tests/segment_tests.rs +++ b/tests/segment_tests.rs @@ -1,22 +1,30 @@ 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(), +fn one_unit_per_nonempty_line() { + let input = "arterielle Hypertonie\nTyp-2-Diabetes mit Polyneuropathie\ngemischte Hyperlipidämie"; + assert_eq!(split_segments(input), vec![ + "arterielle Hypertonie".to_string(), + "Typ-2-Diabetes mit Polyneuropathie".to_string(), + "gemischte Hyperlipidämie".to_string(), ]); } #[test] -fn single_segment_when_no_blank_line() { - assert_eq!(split_segments("nur ein Befund"), vec!["nur ein Befund".to_string()]); +fn blank_and_whitespace_lines_are_skipped_and_each_line_trimmed() { + let input = " \n\n Kreuzschmerz \n \nGonarthrose rechts\n\n"; + assert_eq!(split_segments(input), vec![ + "Kreuzschmerz".to_string(), + "Gonarthrose rechts".to_string(), + ]); } #[test] -fn empty_input_yields_no_segments() { +fn single_phrase_is_one_unit() { + assert_eq!(split_segments("nur eine Diagnose"), vec!["nur eine Diagnose".to_string()]); +} + +#[test] +fn empty_or_whitespace_only_input_yields_no_units() { assert!(split_segments(" \n\n").is_empty()); }