Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: correct and improve verb morphology (#1257)
Andrew Dunbar308d2f94f734
diff --git a/harper-core/affixes.json b/harper-core/affixes.jsonindex 876173413..534c9f371 100644--- a/harper-core/affixes.json+++ b/harper-core/affixes.json@@ -390,7 +390,7 @@},"metadata": {"verb": {- "tense": "Present"+ "verb_form": "ThirdPersonSingularPresentForm"}}}@@ -460,7 +460,7 @@{"metadata": {"verb": {- "tense": "Present"+ "verb_form": "ProgressiveForm"},"noun": null,"adjective": nulldiff --git a/harper-core/src/lib.rs b/harper-core/src/lib.rsindex 1bba22b15..d6ab71f69 100644--- a/harper-core/src/lib.rs+++ b/harper-core/src/lib.rs@@ -48,7 +48,7 @@ pub use token_kind::TokenKind;pub use token_string_ext::TokenStringExt;pub use vec_ext::VecExt;pub use word_metadata::{- AdverbData, ConjunctionData, Degree, Dialect, NounData, PronounData, Tense, VerbData,+ AdverbData, ConjunctionData, Degree, Dialect, NounData, PronounData, VerbData, VerbForm,WordMetadata,};diff --git a/harper-core/src/linting/everyday.rs b/harper-core/src/linting/everyday.rsindex ef6b864d9..1d52ed1e1 100644--- a/harper-core/src/linting/everyday.rs+++ b/harper-core/src/linting/everyday.rs@@ -16,7 +16,7 @@ pub struct Everyday {// TODO Switch to use the .is_progressive_form() method when it's mergedfn is_progressive_form(tok: &Token, src: &[char]) -> bool {tok.kind.is_verb()- && tok.kind.is_present_tense_verb()+ && tok.kind.is_verb_progressive_form()&& tok.span.get_content_string(src)diff --git a/harper-core/src/linting/how_to.rs b/harper-core/src/linting/how_to.rsindex da8f27c29..39496df40 100644--- a/harper-core/src/linting/how_to.rs+++ b/harper-core/src/linting/how_to.rs@@ -25,7 +25,7 @@ impl Default for HowTo {InflectionOfBe::new().or(Box::new(|tok: &Token, src: &[char]| {tok.kind.is_auxiliary_verb()|| tok.kind.is_adjective()- || tok.kind.is_present_tense_verb()+ || tok.kind.is_verb_progressive_form()// Special case for "did" as in "how did you do that?"|| tok.span.get_content_string(src).eq_ignore_ascii_case("did")})),diff --git a/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs b/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rsindex f35ddc523..ef4e977d3 100644--- a/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs+++ b/harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs@@ -22,32 +22,15 @@ impl Default for NoContractionWithVerb {.then(WordSet::new(&["lets", "let"])).then_whitespace();- // Word is only a verb, and not the gerund/present participle/progressive -ing form.- // Only tests the next word after "let".- let non_ing_verb = SequencePattern::default().then(|tok: &Token, source: &[char]| {+ // Match verbs that are only verbs (not also nouns/adjectives) and not in -ing form+ let non_ing_verb = SequencePattern::default().then(|tok: &Token, _src: &[char]| {let Some(Some(meta)) = tok.kind.as_word() else {- // Not a wordreturn false;};-- if !meta.is_verb() || meta.is_noun() || meta.is_adjective() {- // Not a verb, or a verb that's also a noun or adjective- return false;- }-- // TODO affix system currently marks -ing and -s verb forms as present tense- // TODO which is wrong. replace with .is_progressive_form() when it's merged- if meta.is_present_tense_verb() {- // A verb in -s (good) or -ing (bad)- return !tok- .span- .get_content_string(source)- .to_lowercase()- .ends_with("ing");- }-- // A verb lemma or in -ed (good)- true+ meta.is_verb()+ && !meta.is_noun()+ && !meta.is_adjective()+ && !meta.is_verb_progressive_form()});// Ambiguous word is a verb determined by heuristic of following word's part of speechdiff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rsindex 5d75e547b..5a5f36ac5 100644--- a/harper-core/src/token_kind.rs+++ b/harper-core/src/token_kind.rs@@ -2,7 +2,7 @@ use is_macro::Is;use serde::{Deserialize, Serialize};use crate::{- ConjunctionData, NounData, Number, PronounData, Punctuation, Quote, Tense, VerbData,+ ConjunctionData, NounData, Number, PronounData, Punctuation, Quote, VerbData, VerbForm,WordMetadata,};@@ -194,12 +194,51 @@ impl TokenKind {)}- pub fn is_present_tense_verb(&self) -> bool {+ pub fn is_verb_lemma(&self) -> bool {matches!(self,TokenKind::Word(Some(WordMetadata {verb: Some(VerbData {- tense: Some(Tense::Present),+ verb_form: Some(VerbForm::LemmaForm),+ ..+ }),+ ..+ }))+ )+ }++ pub fn is_verb_past_form(&self) -> bool {+ matches!(+ self,+ TokenKind::Word(Some(WordMetadata {+ verb: Some(VerbData {+ verb_form: Some(VerbForm::PastForm),+ ..+ }),+ ..+ }))+ )+ }++ pub fn is_verb_progressive_form(&self) -> bool {+ matches!(+ self,+ TokenKind::Word(Some(WordMetadata {+ verb: Some(VerbData {+ verb_form: Some(VerbForm::ProgressiveForm),+ ..+ }),+ ..+ }))+ )+ }++ pub fn is_verb_third_person_singular_present_form(&self) -> bool {+ matches!(+ self,+ TokenKind::Word(Some(WordMetadata {+ verb: Some(VerbData {+ verb_form: Some(VerbForm::ThirdPersonSingularPresentForm),..}),..diff --git a/harper-core/src/word_metadata.rs b/harper-core/src/word_metadata.rsindex b1400f550..6796734b2 100644--- a/harper-core/src/word_metadata.rs+++ b/harper-core/src/word_metadata.rs@@ -124,11 +124,41 @@ impl WordMetadata {adverb has);- pub fn is_present_tense_verb(&self) -> bool {+ pub fn is_verb_lemma(&self) -> bool {matches!(self.verb,Some(VerbData {- tense: Some(Tense::Present),+ verb_form: Some(VerbForm::LemmaForm),+ ..+ })+ )+ }++ pub fn is_verb_past_form(&self) -> bool {+ matches!(+ self.verb,+ Some(VerbData {+ verb_form: Some(VerbForm::PastForm),+ ..+ })+ )+ }++ pub fn is_verb_progressive_form(&self) -> bool {+ matches!(+ self.verb,+ Some(VerbData {+ verb_form: Some(VerbForm::ProgressiveForm),+ ..+ })+ )+ }++ pub fn is_verb_third_person_singular_present_form(&self) -> bool {+ matches!(+ self.verb,+ Some(VerbData {+ verb_form: Some(VerbForm::ThirdPersonSingularPresentForm),..}))@@ -219,23 +249,34 @@ impl WordMetadata {}}-// TODO currently unused and probably should be changed to the forms of an inflected verb-// TODO - (present, infinitive); -ed (past tense, past participle), -ing (present participle, continuous, progressive)-// TODO irregular verbs can have different forms for past tense and past participle-// TODO -ed forms can act as verbs and adjectives, -ing forms can act as verbs and nouns-// TODO future shares a form with present/infinitive+// These verb forms are morphological variations, distinct from TAM (Tense-Aspect-Mood)+// Each form can be used in various TAM combinations:+// - Lemma form (infinitive, citation form, dictionary form)+// Used in infinitives (e.g., "to sleep"), imperatives (e.g., "sleep!"), and with modals (e.g., "will sleep")+// - Past form (past participle and simple past)+// Used as verbs (e.g., "slept") or adjectives (e.g., "closed door")+// - Progressive form (present participle and gerund)+// Used as verbs (e.g., "sleeping"), nouns (e.g., "sleeping is important"), or adjectives (e.g., "sleeping dog")+// - Third person singular present (-s/-es)+// Used for third person singular subjects (e.g., "he sleeps", "she reads")+//+// Important notes:+// 1. English expresses time through auxiliary verbs, not verb form alone+// 2. Irregular verbs can have different forms for past participle and simple past+// 3. Future is always expressed through auxiliary verbs (e.g., "will sleep", "going to sleep")#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Is, Hash)]-pub enum Tense {- Past,- Present,- // Future,+pub enum VerbForm {+ LemmaForm,+ PastForm,+ ProgressiveForm,+ ThirdPersonSingularPresentForm,}#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]pub struct VerbData {pub is_linking: Option<bool>,pub is_auxiliary: Option<bool>,- pub tense: Option<Tense>,+ pub verb_form: Option<VerbForm>,}impl VerbData {@@ -244,12 +285,11 @@ impl VerbData {Self {is_linking: self.is_linking.or(other.is_linking),is_auxiliary: self.is_auxiliary.or(other.is_auxiliary),- tense: self.tense.or(other.tense),+ verb_form: self.verb_form.or(other.verb_form),}}}-// TODO renamed from "noun" until refactoring is complete// TODO other noun properties may be worth adding:// TODO count vs mass; abstract#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]