refactor: input contract — one extracted phrase per line (spec §1a)

split_segments now treats each non-empty trimmed line as one retrieval
unit; blank lines are skipped, not paragraph delimiters. Name/signature
retained (minimal-churn decision). Full suite 45/0. End-to-end: feeding
the GP dictation as extracted phrases recovers I10.90 (rank 4) which was
entirely missing in both modes under the paragraph contract, and largely
dissolves the cross-segment diabetes crowding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 23:30:05 +02:00
parent 7cec295d99
commit f047cd1b5b
2 changed files with 30 additions and 29 deletions
+12 -19
View File
@@ -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<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()
/// 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<String> {
phrases
.lines()
.map(|l| l.trim())
.filter(|l| !l.is_empty())
.map(|l| l.to_string())
.collect()
}
+18 -10
View File
@@ -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());
}