Skip to content

Commit 77cfccb

Browse files
author
Ed Page
committed
refactor(varcon): Clarify check's meanings
1 parent fa7ce95 commit 77cfccb

File tree

1 file changed

+10
-8
lines changed
  • crates/typos-dict/verify/src

1 file changed

+10
-8
lines changed

crates/typos-dict/verify/src/main.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use structopt::StructOpt;
66
fn generate<W: std::io::Write>(file: &mut W, dict: &[u8]) {
77
let mut wtr = csv::Writer::from_writer(file);
88

9-
let disallowed_typos = disallowed_typos();
10-
let related_words = related_words();
9+
let disallowed_typos = varcon_words();
10+
let word_variants = proper_word_variants();
1111

1212
let mut reader = csv::ReaderBuilder::new()
1313
.has_headers(false)
@@ -19,7 +19,7 @@ fn generate<W: std::io::Write>(file: &mut W, dict: &[u8]) {
1919
if disallowed_typos.contains(&unicase::UniCase::new(typo)) {
2020
continue;
2121
}
22-
let correction = related_words
22+
let correction = word_variants
2323
.get(correction)
2424
.and_then(|words| find_best_match(typo, correction, words))
2525
.unwrap_or(correction);
@@ -28,7 +28,9 @@ fn generate<W: std::io::Write>(file: &mut W, dict: &[u8]) {
2828
wtr.flush().unwrap();
2929
}
3030

31-
fn disallowed_typos() -> HashSet<unicase::UniCase<&'static str>> {
31+
fn varcon_words() -> HashSet<unicase::UniCase<&'static str>> {
32+
// Even include improper ones because we should be letting varcon handle that rather than our
33+
// dictionary
3234
varcon::VARCON
3335
.iter()
3436
.flat_map(|c| c.entries.iter())
@@ -37,7 +39,7 @@ fn disallowed_typos() -> HashSet<unicase::UniCase<&'static str>> {
3739
.collect()
3840
}
3941

40-
fn related_words() -> HashMap<&'static str, HashSet<&'static str>> {
42+
fn proper_word_variants() -> HashMap<&'static str, HashSet<&'static str>> {
4143
let mut words: HashMap<&'static str, HashSet<&'static str>> = HashMap::new();
4244
for entry in varcon::VARCON.iter().flat_map(|c| c.entries.iter()) {
4345
let variants: HashSet<_> = entry
@@ -57,11 +59,11 @@ fn related_words() -> HashMap<&'static str, HashSet<&'static str>> {
5759
fn find_best_match<'c>(
5860
typo: &'c str,
5961
correction: &'c str,
60-
related_words: &HashSet<&'static str>,
62+
word_variants: &HashSet<&'static str>,
6163
) -> Option<&'c str> {
62-
assert!(!related_words.contains(correction));
64+
assert!(!word_variants.contains(correction));
6365
let current = edit_distance::edit_distance(typo, correction);
64-
let mut matches: Vec<_> = related_words
66+
let mut matches: Vec<_> = word_variants
6567
.iter()
6668
.map(|r| (edit_distance::edit_distance(typo, r), *r))
6769
.filter(|(d, _)| *d < current)

0 commit comments

Comments
 (0)