mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 22:40:09 +01:00
chore: dynamic linguistic distance
This commit is contained in:
parent
d4c97333ba
commit
0d8786f5a1
1 changed files with 8 additions and 2 deletions
|
|
@ -177,24 +177,30 @@ pub fn suggest_typo(typos: &[String], candidates: Vec<String>) -> String {
|
||||||
};
|
};
|
||||||
if let Some(suggest) = find_similar(typo, &path_files) {
|
if let Some(suggest) = find_similar(typo, &path_files) {
|
||||||
suggestions.push(suggest);
|
suggestions.push(suggest);
|
||||||
};
|
} else {
|
||||||
|
suggestions.push(typo.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"file" => {
|
"file" => {
|
||||||
if let Some(suggest) = get_best_match_file(typo) {
|
if let Some(suggest) = get_best_match_file(typo) {
|
||||||
suggestions.push(suggest);
|
suggestions.push(suggest);
|
||||||
|
} else {
|
||||||
|
suggestions.push(typo.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else if let Some(suggest) = find_similar(typo, &candidates) {
|
} else if let Some(suggest) = find_similar(typo, &candidates) {
|
||||||
suggestions.push(suggest);
|
suggestions.push(suggest);
|
||||||
|
} else {
|
||||||
|
suggestions.push(typo.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
suggestions.join(" ")
|
suggestions.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_similar(typo: &str, candidates: &[String]) -> Option<String> {
|
pub fn find_similar(typo: &str, candidates: &[String]) -> Option<String> {
|
||||||
let mut min_distance = 10;
|
let mut min_distance = { std::cmp::max(2, typo.chars().count() / 2 + 1) };
|
||||||
let mut min_distance_index = None;
|
let mut min_distance_index = None;
|
||||||
for (i, candidate) in candidates.iter().enumerate() {
|
for (i, candidate) in candidates.iter().enumerate() {
|
||||||
if candidate.is_empty() {
|
if candidate.is_empty() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue