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(" ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user