Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(fst-dict): make some corrections based on PR review

Grant Lemonse05d2eed580e
diff --git a/Cargo.lock b/Cargo.lock
index 8342e6c2f..b43018a8a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -619,18 +619,12 @@ dependencies = [
name = "harper-dictionary-parsing"
version = "0.12.0"
dependencies = [
- "blanket",
"hashbrown 0.15.0",
"is-macro",
- "itertools 0.13.0",
- "ordered-float",
- "paste",
"serde",
"serde_json",
"smallvec",
"thiserror",
- "unicode-blocks",
- "unicode-width 0.2.0",
]
[[package]]
diff --git a/harper-core/build.rs b/harper-core/build.rs
index 735b273bc..996df9bd9 100644
--- a/harper-core/build.rs
+++ b/harper-core/build.rs
@@ -27,8 +27,6 @@ fn main() {
words.dedup();
words.sort_by_key(|w| w.len()); // DO NOT MAKE THIS UNSTABLE.
- // Using u64 shouldn't pose any issues since I don't think the English
- // language has that many words
words
.iter()
.enumerate()
diff --git a/harper-core/src/spell/full_dictionary.rs b/harper-core/src/spell/full_dictionary.rs
index 07e4a8405..8d3a5f038 100644
--- a/harper-core/src/spell/full_dictionary.rs
+++ b/harper-core/src/spell/full_dictionary.rs
@@ -67,7 +67,8 @@ impl FullDictionary {
/// Create a dictionary from the curated dictionary included
/// in the Harper binary.
- pub(super) fn curated() -> Arc<Self> {
+ /// Consider using [`FstDictionary::curated()`] instead, as it is more performant for spellchecking.
+ pub fn curated() -> Arc<Self> {
DICT.with(|v| v.clone())
}
@@ -180,8 +181,11 @@ impl Dictionary for FullDictionary {
) -> Vec<(&[char], u8, WordMetadata)> {
let misspelled_charslice = seq_to_normalized(word);
- let shortest_word_len =
- std::cmp::max(1, misspelled_charslice.len() - max_distance as usize);
+ let shortest_word_len = if misspelled_charslice.len() <= max_distance as usize {
+ 1
+ } else {
+ misspelled_charslice.len() - max_distance as usize
+ };
let longest_word_len = misspelled_charslice.len() + max_distance as usize;
// Get canidate words
diff --git a/harper-core/src/spell/mod.rs b/harper-core/src/spell/mod.rs
index b964f88a7..fd68947e7 100644
--- a/harper-core/src/spell/mod.rs
+++ b/harper-core/src/spell/mod.rs
@@ -337,62 +337,6 @@ mod tests {
assert!(results.iter().take(3).contains(&"about".to_string()));
}
- #[test]
- fn fst_spellcheck_match() {
- let results = suggest_correct_spelling_str(
- "hello",
- RESULT_LIMIT,
- MAX_EDIT_DIST,
- &FstDictionary::curated(),
- );
-
- dbg!(&results);
-
- assert!(results.iter().take(3).contains(&"hello".to_string()));
- }
-
- #[test]
- fn full_spellcheck_match() {
- let results = suggest_correct_spelling_str(
- "hello",
- RESULT_LIMIT,
- MAX_EDIT_DIST,
- &FullDictionary::curated(),
- );
-
- dbg!(&results);
-
- assert!(results.iter().take(3).contains(&"hello".to_string()));
- }
-
- #[test]
- fn fst_spellcheck_capital() {
- let results = suggest_correct_spelling_str(
- "Hello",
- RESULT_LIMIT,
- MAX_EDIT_DIST,
- &FstDictionary::curated(),
- );
-
- dbg!(&results);
-
- assert!(results.iter().take(3).contains(&"hello".to_string()));
- }
-
- #[test]
- fn full_spellcheck_capital() {
- let results = suggest_correct_spelling_str(
- "Hello",
- RESULT_LIMIT,
- MAX_EDIT_DIST,
- &FullDictionary::curated(),
- );
-
- dbg!(&results);
-
- assert!(results.iter().take(3).contains(&"hello".to_string()));
- }
-
#[test]
fn spellchecking_is_deterministic() {
let results1 = suggest_correct_spelling_str(
diff --git a/harper-dictionary-parsing/Cargo.toml b/harper-dictionary-parsing/Cargo.toml
index b7feede14..1b6de9a07 100644
--- a/harper-dictionary-parsing/Cargo.toml
+++ b/harper-dictionary-parsing/Cargo.toml
@@ -7,15 +7,9 @@ license = "Apache-2.0"
repository = "https://github.com/elijah-potter/harper"
[dependencies]
-blanket = "0.4.0"
hashbrown = { version = "0.15.0", features = ["serde"] }
is-macro = "0.3.6"
-itertools = "0.13.0"
-ordered-float = { version = "4.4.0", features = ["serde"] }
-paste = "1.0.14"
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.132"
smallvec = { version = "1.13.2", features = ["serde"] }
thiserror = "1.0.65"
-unicode-blocks = "0.1.9"
-unicode-width = "0.2.0"