Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ability to have numbers in English checker #174

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/checkers/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ impl Check for Checker<EnglishChecker> {
link: self.link,
};

// After we've normalised our string, if we find it's a length 0 we don't do anything
// After we've normalised our string, if we find it's a length 2 we don't do anything
// This can happen if our string is a single puncuation mark, for example.
if input.is_empty() {
// There are no words of length 2 or more in the dict, so it's not worth checking.
if input.len() < 2 {
return result;
}

Expand Down Expand Up @@ -106,6 +107,9 @@ fn normalise_string(input: &str) -> String {
.to_ascii_lowercase()
.chars()
.filter(|x| !x.is_ascii_punctuation())
// if digit is base10 filter it out
// Our dictionary does not contain numbers, so we want to filter them out
.filter(|x| !x.is_ascii_digit())
.collect()
}

Expand Down Expand Up @@ -187,4 +191,16 @@ mod tests {
let checker = Checker::<EnglishChecker>::new();
assert!(!checker.check("#").is_identified);
}

#[test]
fn test_check_fail_single_number() {
let checker = Checker::<EnglishChecker>::new();
assert!(!checker.check("2").is_identified);
}

#[test]
fn test_check_fail_single_letter() {
let checker = Checker::<EnglishChecker>::new();
assert!(!checker.check("F").is_identified);
}
}
3 changes: 3 additions & 0 deletions src/storage/dictionaries/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
f = open(file_name)
f2 = open("modified.txt", "w")
for line in f:
line = line.strip()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of our words when opened in file mode had spaces in them, this messed up my analysis of them which led to some single chars (a) being included because their length was actually > 2 due to having multiple spaces

if len(line) <= MIN_LENGTH:
continue
if len(set(line).intersection(PUNC)) != 0:
continue
if not line.isalpha():
continue
if LOWERCASE:
line = line.lower()
f2.write(line)
Expand Down
Loading