Skip to content

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

feat: methods for matching sg/pl nouns that are not both (#4319)

Andrew Dunbar5fe7d5ab7649
diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dict
index a69ad1154..b08248e30 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -37953,12 +37953,13 @@ owlish/JY
own/~JVGdSNE
owner/~NgS
ownership/~Nmg
-ox/~Ngn
+ox/~N0gn
oxalate/~NV
oxalis/NgS
oxblood/NgJ
oxbow/~NgS
oxcart/NSg
+oxen/N9
oxford/~NSg
oxidant/NgS
oxidase/~N
diff --git a/harper-core/src/dict_word_metadata.rs b/harper-core/src/dict_word_metadata.rs
index 4e1e0e0c5..52de13cdd 100644
--- a/harper-core/src/dict_word_metadata.rs
+++ b/harper-core/src/dict_word_metadata.rs
@@ -582,6 +582,28 @@ impl DictWordMetadata {
}
}
+ pub fn is_singular_noun_only(&self) -> bool {
+ if let Some(noun) = self.noun {
+ matches!(
+ (noun.is_singular, noun.is_plural),
+ (Some(true), None | Some(false))
+ )
+ } else {
+ false
+ }
+ }
+
+ pub fn is_plural_noun_only(&self) -> bool {
+ if let Some(noun) = self.noun {
+ matches!(
+ (noun.is_singular, noun.is_plural),
+ (None | Some(false), Some(true))
+ )
+ } else {
+ false
+ }
+ }
+
// Most mass nouns also have countable senses. Match those that are only mass nouns.
pub fn is_mass_noun_only(&self) -> bool {
if let Some(noun) = self.noun {
@@ -1974,6 +1996,36 @@ pub mod tests {
assert!(!md("equipment").is_countable_noun());
}
+ #[test]
+ fn infrastructure_is_mass_noun_only() {
+ assert!(md("infrastructure").is_mass_noun_only());
+ }
+
+ #[test]
+ fn beer_is_not_mass_noun_only() {
+ assert!(!md("beer").is_mass_noun_only());
+ }
+
+ #[test]
+ fn sheep_is_not_singular_only() {
+ assert!(!md("sheep").is_singular_noun_only());
+ }
+
+ #[test]
+ fn sheep_is_not_plural_only() {
+ assert!(!md("sheep").is_plural_noun_only());
+ }
+
+ #[test]
+ fn ox_is_singular_only() {
+ assert!(md("ox").is_singular_noun_only());
+ }
+
+ #[test]
+ fn oxen_is_plural_only() {
+ assert!(md("oxen").is_plural_noun_only());
+ }
+
mod verb {
use crate::dict_word_metadata::tests::md;
diff --git a/harper-core/src/expr/sequence_expr.rs b/harper-core/src/expr/sequence_expr.rs
index eb9b3ded2..02036837f 100644
--- a/harper-core/src/expr/sequence_expr.rs
+++ b/harper-core/src/expr/sequence_expr.rs
@@ -585,8 +585,10 @@ impl SequenceExpr {
gen_then_from_is!(noun);
gen_then_from_is!(proper_noun);
- gen_then_from_is!(plural_noun);
gen_then_from_is!(singular_noun);
+ gen_then_from_is!(plural_noun);
+ gen_then_from_is!(singular_noun_only);
+ gen_then_from_is!(plural_noun_only);
gen_then_from_is!(mass_noun_only);
// Pronouns
diff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rs
index 8370380fc..17ad9fa95 100644
--- a/harper-core/src/token_kind.rs
+++ b/harper-core/src/token_kind.rs
@@ -68,7 +68,9 @@ impl TokenKind {
is_possessive_nominal,
is_non_plural_nominal,
is_singular_noun,
+ is_singular_noun_only,
is_plural_noun,
+ is_plural_noun_only,
is_non_plural_noun,
is_non_possessive_noun,
is_countable_noun,