feat: text normalization with medical abbreviation expansion

This commit is contained in:
2026-05-18 16:36:06 +02:00
parent c8ea9a5fb3
commit 9f3e79c874
2 changed files with 40 additions and 1 deletions
+23 -1
View File
@@ -1 +1,23 @@
// implemented in a later task /// (pattern, replacement) — applied as whole-token, case-insensitive.
const ABBREV: &[(&str, &str)] = &[
("v.a.", "verdacht auf"),
("z.n.", "zustand nach"),
("art.", "arterielle"),
("op", "operation"),
("dd", "differentialdiagnose"),
("re.", "rechts"),
("li.", "links"),
];
pub fn normalize(input: &str) -> String {
let lower = input.to_lowercase();
let mut out: Vec<String> = Vec::new();
for tok in lower.split_whitespace() {
let replaced = ABBREV.iter()
.find(|(p, _)| *p == tok)
.map(|(_, r)| r.to_string())
.unwrap_or_else(|| tok.to_string());
out.push(replaced);
}
out.join(" ")
}
+17
View File
@@ -0,0 +1,17 @@
use alpha_id::normalize::normalize;
#[test]
fn lowercases_and_collapses_whitespace() {
assert_eq!(normalize(" Diabetes Mellitus\tTyp 2 "), "diabetes mellitus typ 2");
}
#[test]
fn expands_common_medical_abbreviations() {
assert_eq!(normalize("V.a. art. Hypertonie"), "verdacht auf arterielle hypertonie");
assert_eq!(normalize("Z.n. OP"), "zustand nach operation");
}
#[test]
fn keeps_german_umlauts() {
assert_eq!(normalize("Ödem"), "ödem");
}