Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: expression to match pronoun-be, word pair or contraction (#2944)
Andrew Dunbar532af5c9ed26
diff --git a/Cargo.lock b/Cargo.lockindex d0d13b2ed..16acb7197 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3511,9 +3511,9 @@ dependencies = [[[package]]name = "libc"-version = "0.2.183"+version = "0.2.174"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"+checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"[[package]]name = "libfuzzer-sys"@@ -3584,9 +3584,9 @@ dependencies = [[[package]]name = "linux-raw-sys"-version = "0.12.1"+version = "0.9.4"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"+checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"[[package]]name = "litemap"@@ -4839,15 +4839,15 @@ dependencies = [[[package]]name = "rustix"-version = "1.1.4"+version = "1.0.8"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"+checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"dependencies = ["bitflags 2.11.0","errno","libc","linux-raw-sys",- "windows-sys 0.61.1",+ "windows-sys 0.60.2",][[package]]@@ -5372,15 +5372,15 @@ dependencies = [[[package]]name = "tempfile"-version = "3.27.0"+version = "3.20.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"+checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"dependencies = ["fastrand",- "getrandom 0.4.1",+ "getrandom 0.3.4","once_cell","rustix",- "windows-sys 0.61.1",+ "windows-sys 0.59.0",][[package]]diff --git a/harper-core/src/expr/mod.rs b/harper-core/src/expr/mod.rsindex 082866eb9..3d0354d1c 100644--- a/harper-core/src/expr/mod.rs+++ b/harper-core/src/expr/mod.rs@@ -24,6 +24,7 @@ mod fixed_phrase;mod longest_match_of;mod mergeable_words;mod optional;+mod pronoun_be;mod reflexive_pronoun;mod repeating;mod sequence_expr;@@ -50,6 +51,7 @@ pub use fixed_phrase::FixedPhrase;pub use longest_match_of::LongestMatchOf;pub use mergeable_words::MergeableWords;pub use optional::Optional;+pub use pronoun_be::PronounBe;pub use reflexive_pronoun::ReflexivePronoun;pub use repeating::Repeating;pub use sequence_expr::SequenceExpr;diff --git a/harper-core/src/expr/pronoun_be.rs b/harper-core/src/expr/pronoun_be.rsnew file mode 100644index 000000000..8b68fa37d--- /dev/null+++ b/harper-core/src/expr/pronoun_be.rs@@ -0,0 +1,158 @@+use crate::{Span, Token, patterns::WordSet};++use super::{Expr, SequenceExpr};++pub struct PronounBe {+ expr: SequenceExpr,+}++impl Default for PronounBe {+ fn default() -> Self {+ Self {+ expr: SequenceExpr::default().then_any_of(vec![+ Box::new(+ SequenceExpr::default()+ .then_subject_pronoun()+ .t_ws()+ .t_set(&["am", "are", "is", "was", "were"]),+ ),+ Box::new(WordSet::new(&[+ "i'm", "we're", "you're", "he's", "she's", "it's", "they're",+ ])),+ ]),+ }+ }+}++impl Expr for PronounBe {+ fn run(&self, cursor: usize, toks: &[Token], src: &[char]) -> Option<Span<Token>> {+ if toks.is_empty() {+ return None;+ }++ self.expr.run(cursor, toks, src)+ }+}++#[cfg(test)]+mod tests {+ use crate::{+ Document,+ expr::{ExprExt, PronounBe},+ };++ fn assert_count(text: &str, expected_count: usize) {+ assert_eq!(+ PronounBe::default()+ .iter_matches_in_doc(&Document::new_plain_english_curated(text))+ .count(),+ expected_count+ );+ }++ #[test]+ fn ok_i_am() {+ assert_count("I am an auditor of software in M&A.", 1);+ }++ #[test]+ fn ok_i_m() {+ assert_count(+ "I'm using Beads in every new project and adding it to every old project I visit with an agent.",+ 1,+ );+ }++ #[test]+ fn ok_we_are() {+ assert_count(+ "Error: we are enable to complete your request at this time.",+ 1,+ );+ }++ #[test]+ fn ok_we_re() {+ assert_count(+ "We're currently experiencing high demand, which may cause temporary errors.",+ 1,+ );+ }++ #[test]+ fn ok_you_are() {+ assert_count(+ "You are Dolphin, an uncensored and unbiased AI assistant.",+ 1,+ );+ }++ #[test]+ fn ok_you_re() {+ assert_count(+ "You're trying to use a SD1 LoRA model with a SDXL Stable Diffusion model.",+ 1,+ );+ }++ #[test]+ fn ok_he_is() {+ assert_count("He is just a modulary guy for checking service health.", 1);+ }++ #[test]+ fn ok_he_s_and_it_is() {+ assert_count(+ "He's Dead, Jim is a link checking program, specifically it is a command-line tool for finding and reporting dead links",+ 2,+ );+ }++ #[test]+ fn ok_she_is() {+ assert_count(+ "SHE is designed by following the SHE functional specification.",+ 1,+ );+ }++ #[test]+ fn ok_she_s() {+ assert_count(+ "She's Coding is an open-source website project currently under development in cooperation with the documentary film CODE: Debugging the Gender Gap.",+ 1,+ );+ }++ #[test]+ fn ok_it_is() {+ assert_count("It is same as ms-dos command where.exe.", 1);+ }++ #[test]+ fn ok_it_s_and_you_are() {+ assert_count(+ "It's not working · Microcontrollers have only a limited amount of RAM: Verify that you are not running out of available RAM!",+ 2,+ );+ }++ #[test]+ fn ok_they_are() {+ assert_count(+ "Multidist binaries ignore the way they are called and check only the running binary name, making them hard to invoke from a single one.",+ 1,+ );+ }++ #[test]+ fn ok_they_re() {+ assert_count("Cannot load dataset, they're greyed out.", 1);+ }++ #[test]+ fn various_apostrophes() {+ assert_count("it's/it’s", 2);+ assert_count("it;s/it´s", 0);+ }+}