Skip to content

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

Add verb past form only helpers (#3379)

Tonchain51121cc3a728
diff --git a/harper-core/src/dict_word_metadata.rs b/harper-core/src/dict_word_metadata.rs
index 97cc96591..6864f6d28 100644
--- a/harper-core/src/dict_word_metadata.rs
+++ b/harper-core/src/dict_word_metadata.rs
@@ -480,6 +480,14 @@ impl DictWordMetadata {
})
}
+ pub fn is_verb_regular_past_form(&self) -> bool {
+ self.verb.is_some_and(|v| {
+ v.verb_forms.is_some_and(|vf| {
+ vf.contains(VerbFormFlags::PRETERITE) && vf.contains(VerbFormFlags::PAST_PARTICIPLE)
+ })
+ })
+ }
+
pub fn is_verb_simple_past_form(&self) -> bool {
self.verb.is_some_and(|v| {
v.verb_forms
@@ -494,6 +502,24 @@ impl DictWordMetadata {
})
}
+ pub fn is_verb_simple_past_only(&self) -> bool {
+ self.verb.is_some_and(|v| {
+ v.verb_forms.is_some_and(|vf| {
+ vf.contains(VerbFormFlags::PRETERITE)
+ && !vf.intersects(VerbFormFlags::PAST | VerbFormFlags::PAST_PARTICIPLE)
+ })
+ })
+ }
+
+ pub fn is_verb_past_participle_only(&self) -> bool {
+ self.verb.is_some_and(|v| {
+ v.verb_forms.is_some_and(|vf| {
+ vf.contains(VerbFormFlags::PAST_PARTICIPLE)
+ && !vf.intersects(VerbFormFlags::PAST | VerbFormFlags::PRETERITE)
+ })
+ })
+ }
+
pub fn is_verb_progressive_form(&self) -> bool {
self.verb.is_some_and(|v| {
v.verb_forms
@@ -1963,6 +1989,12 @@ pub mod tests {
assert!(md.is_verb_past_form())
}
+ #[test]
+ fn regular_past_thought() {
+ let md = md("thought");
+ assert!(md.is_verb_regular_past_form())
+ }
+
#[test]
fn simple_past_ate() {
let md = md("ate");
@@ -1975,6 +2007,42 @@ pub mod tests {
assert!(md.is_verb_past_participle_form())
}
+ #[test]
+ fn ate_is_simple_past_only() {
+ let md = md("ate");
+ assert!(md.is_verb_simple_past_only());
+ assert!(!md.is_verb_past_participle_only());
+ }
+
+ #[test]
+ fn eaten_is_past_participle_only() {
+ let md = md("eaten");
+ assert!(md.is_verb_past_participle_only());
+ assert!(!md.is_verb_simple_past_only());
+ }
+
+ #[test]
+ fn thought_is_neither_past_form_only() {
+ let md = md("thought");
+ assert!(!md.is_verb_simple_past_only());
+ assert!(!md.is_verb_past_participle_only());
+ }
+
+ #[test]
+ fn shared_past_forms_are_neither_past_form_only() {
+ let md = md("thought");
+ assert!(!md.is_verb_simple_past_only());
+ assert!(!md.is_verb_past_participle_only());
+ assert!(md.is_verb_regular_past_form());
+ }
+
+ #[test]
+ fn distinct_past_forms_are_not_regular_past() {
+ assert!(!md("ate").is_verb_regular_past_form());
+ assert!(!md("eaten").is_verb_regular_past_form());
+ assert!(!md("walked").is_verb_regular_past_form());
+ }
+
#[test]
fn third_pers_sing_walks() {
let md = md("walks");
diff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rs
index 3a7b763c6..a5b0f7e4d 100644
--- a/harper-core/src/token_kind.rs
+++ b/harper-core/src/token_kind.rs
@@ -99,8 +99,11 @@ impl TokenKind {
is_linking_verb,
is_verb_lemma,
is_verb_past_form,
+ is_verb_regular_past_form,
is_verb_simple_past_form,
is_verb_past_participle_form,
+ is_verb_simple_past_only,
+ is_verb_past_participle_only,
is_verb_progressive_form,
is_verb_third_person_singular_present_form,
@@ -435,6 +438,29 @@ mod tests {
assert!(!tk.is_countable_noun());
}
+ #[test]
+ fn ate_is_simple_past_only() {
+ let doc = Document::new_plain_english_curated("ate");
+ let tk = &doc.tokens().next().unwrap().kind;
+ assert!(tk.is_verb_simple_past_only());
+ assert!(!tk.is_verb_past_participle_only());
+ }
+
+ #[test]
+ fn eaten_is_past_participle_only() {
+ let doc = Document::new_plain_english_curated("eaten");
+ let tk = &doc.tokens().next().unwrap().kind;
+ assert!(tk.is_verb_past_participle_only());
+ assert!(!tk.is_verb_simple_past_only());
+ }
+
+ #[test]
+ fn thought_is_regular_past_form() {
+ let doc = Document::new_plain_english_curated("thought");
+ let tk = &doc.tokens().next().unwrap().kind;
+ assert!(tk.is_verb_regular_past_form());
+ }
+
#[test]
fn oov_word_is_oov() {
let doc = Document::new_plain_english_curated("nonexistentword");