Skip to content

Commit

Permalink
fix(dict): Remove nilable
Browse files Browse the repository at this point in the history
See conversation in #613
  • Loading branch information
epage committed Dec 6, 2022
1 parent 46839a3 commit c963f68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions crates/typos-dict/assets/allowed.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nilable,used in ruby community
thead,html tag
hardlinked,filesystem term
1 change: 0 additions & 1 deletion crates/typos-dict/assets/words.csv
Original file line number Diff line number Diff line change
Expand Up @@ -33022,7 +33022,6 @@ nigthmares,nightmares
nihilim,nihilism
nihilisim,nihilism
nihilsim,nihilism
nilable,nillable
nilihism,nihilism
nimutes,minutes
nin,inn,min,bin,nine
Expand Down
2 changes: 0 additions & 2 deletions crates/typos-dict/src/dict_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68764,7 +68764,6 @@ pub static WORD_NI_CHILDREN: dictgen::DictTable<&'static [&'static str]> = dictg
dictgen::InsensitiveStr::Ascii("hilim"),
dictgen::InsensitiveStr::Ascii("hilisim"),
dictgen::InsensitiveStr::Ascii("hilsim"),
dictgen::InsensitiveStr::Ascii("lable"),
dictgen::InsensitiveStr::Ascii("lihism"),
dictgen::InsensitiveStr::Ascii("mutes"),
dictgen::InsensitiveStr::Ascii("n"),
Expand Down Expand Up @@ -68817,7 +68816,6 @@ pub static WORD_NI_CHILDREN: dictgen::DictTable<&'static [&'static str]> = dictg
&["nihilism"],
&["nihilism"],
&["nihilism"],
&["nillable"],
&["nihilism"],
&["minutes"],
&["inn", "min", "bin", "nine"],
Expand Down
34 changes: 31 additions & 3 deletions crates/typos-dict/tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,26 @@ fn generate<W: std::io::Write>(file: &mut W, dict: &[u8]) {
})
.collect();

let disallowed_typos = varcon_words();
let varcon_words = varcon_words();
let allowed_words = allowed_words();
let word_variants = proper_word_variants();
let rows: Dict = rows
.into_iter()
.filter(|(typo, _)| {
let is_disallowed = disallowed_typos.contains(&unicase::UniCase::new(typo));
let is_disallowed = varcon_words.contains(&unicase::UniCase::new(typo));
if is_disallowed {
eprintln!("{:?} is disallowed", typo);
eprintln!("{:?} is disallowed; in varcon", typo);
}
!is_disallowed
})
.filter(|(typo, _)| {
if let Some(reason) = allowed_words.get(typo.as_ref()) {
eprintln!("{:?} is disallowed; {}", typo, reason);
false
} else {
true
}
})
.map(|(typo, corrections)| {
let mut new_corrections = vec![];
for correction in corrections {
Expand Down Expand Up @@ -137,3 +146,22 @@ fn find_best_match<'c>(
matches.sort_unstable();
matches.into_iter().next().map(|(_, r)| r)
}

fn allowed_words() -> std::collections::HashMap<String, String> {
let allowed_path = "assets/allowed.csv";
let data = std::fs::read(allowed_path).unwrap();
csv::ReaderBuilder::new()
.has_headers(false)
.flexible(true)
.from_reader(data.as_slice())
.records()
.map(Result::unwrap)
.map(|r| {
let mut i = r.iter();
let mut typo = i.next().expect("typo").to_owned();
typo.make_ascii_lowercase();
let reason = i.next().expect("reason").to_owned();
(typo, reason)
})
.collect()
}

0 comments on commit c963f68

Please sign in to comment.