feat: text normalization with medical abbreviation expansion
This commit is contained in:
+23
-1
@@ -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(" ")
|
||||||
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user