Skip to content

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

Merge branch 'master' into noun-to-nominal

Elijah Potter6545d9139756
diff --cc harper-core/affixes.json
index 70fb5e5b8,85b01c0fe..15e35ed2e
--- a/harper-core/affixes.json
+++ b/harper-core/affixes.json
@@@ -645,100 -646,17 +645,112 @@@
"adverb": {}
}
},
+ "s": {
+ "#": "subject case property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {}
+ }
+ },
+ "o": {
+ "#": "object case property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {}
+ }
+ },
+ "f": {
+ "#": "first-person property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {}
+ }
+ },
+ "n": {
+ "#": "second-person property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {}
+ }
+ },
+ "t": {
+ "#": "third-person property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {}
+ }
+ },
+ "c": {
+ "#": "comparative property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "adjective": {}
+ }
+ },
+ "u": {
+ "#": "superlative property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "adjective": {}
+ }
+ },
+ "*": {
+ "#": "singular third-person pronoun property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {
+ "is_plural": false,
+ "person": "Third"
+ }
+ }
+ },
+ ":": {
+ "#": "plural pronoun property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "pronoun": {
+ "is_plural": true
+ }
+ }
++ },
+ "m": {
+ "#": "auxiliary verb property",
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "verb": {
+ "is_auxiliary": true
+ }
+ }
}
}
}
diff --cc harper-core/dictionary.dict
index 40a26589d,538614fa2..71ab7ee44
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@@ -10773,7 -10858,7 +10858,7 @@@ Zworykin/
Zyrtec/M
Zyuganov/M
Zzz
- a/-~
-a/-+57~
++a/-~+
as/j
aah/14
aardvark/1SM
@@@ -13921,7 -13987,7 +13987,7 @@@ bespeak/41S
bespectacled/5
bespoke/54
bespoken/45
- best/514SGMDu
-best/51mSGMD
++best/514SGMDum
bestial/51Y
bestiality/1M
bestiary/1SM
@@@ -13956,7 -14022,7 +14022,8 @@@ betroth/4D
betrothal/1SM
betrothed/451M
betroths/4
- better/514MDGLSc
-better/51mMDGLS
++better/514MDGLScm
++better/51MDGLS
betterment/1M
betting/541
bettor/1MS
@@@ -31613,10 -31677,10 +31683,10 @@@ mechanical/51Y
mechanics/1M
mechanism/1SM
mechanistic/5
- mechanistically/
+ mechanistically/j
mechanization/1M
mechanize/4DSG
-med/1MS
+med/1SM
medal/14SM
medalist/1MS
medallion/14SM
@@@ -33092,10 -33166,10 +33172,10 @@@ mutual/51
mutuality/1M
muumuu/1MS
muzak/14
- muzzily/
+ muzzily/j
muzzle/14DSMG
muzzy/51P
-my/~5
+my/~-
mycologist/1SM
mycology/1M
myelitis/1M
@@@ -34761,11 -34846,10 +34852,11 @@@ otter/1M
ottoman/1MS
oubliette/1MS
ouch/14
- ought/481
- oughtn't/4
+ ought/m81
+ oughtn't/m
ounce/1MS
-our/4S~
+our/~-
+ours/8
ourselves/8
oust/4ZGDRS
ouster/14M
@@@ -45518,9 -45630,8 +45639,9 @@@ theirs/
theism/1M
theist/1SM
theistic/5
-them/8~
+them/8~ot
- thematic/51
+ thematic/51Q
+thematically/
theme/14DSM
themselves/8
then/517M~
@@@ -45580,12 -45692,10 +45702,11 @@@ thermonuclear/5
thermoplastic/51SM
thermos/1MS
thermostat/1MS
- thermostatic/5
- thermostatically/
+ thermostatic/5Q
thesauri/1
thesaurus/1MS
-these/8S~9
+these/8~-
+theses/9M
thesis/1M
thespian/51SM
theta/1SM
@@@ -47343,12 -47474,12 +47485,13 @@@ unionism/1
unionist/51MS
unique/51YTRP
uniqueness/1M
+ unironic/5Q
unisex/51M
unison/1M
+unit/1SM
unitary/51
unite/41AEGSD
- unitedly/
+ unitedly/j
unities/1
unitize/4DSG
unity/1EM
diff --cc harper-core/src/document.rs
index fc5a88640,53a2625f0..9f1abbaf1
--- a/harper-core/src/document.rs
+++ b/harper-core/src/document.rs
@@@ -91,7 -91,7 +91,7 @@@ impl Document
}
/// Parse text to produce a document using the built-in [`Markdown`] parser
-- /// and curated dictionary with the default markdown configuration.
++ /// and curated dictionary with the default Markdown configuration.
pub fn new_markdown_default_curated(text: &str) -> Self {
Self::new_markdown_curated(text, MarkdownOptions::default())
}
@@@ -107,7 -107,7 +107,7 @@@
}
/// Parse text to produce a document using the built-in [`PlainEnglish`]
-- /// parser and the curated dictionary with the default markdown configuration.
++ /// parser and the curated dictionary with the default Markdown configuration.
pub fn new_markdown_default(text: &str, dictionary: &impl Dictionary) -> Self {
Self::new_markdown(text, MarkdownOptions::default(), dictionary)
}
@@@ -135,6 -136,32 +136,32 @@@
}
}
+ fn uncached_article_pattern() -> Lrc<SequencePattern> {
+ Lrc::new(
+ SequencePattern::default()
- .then_article()
++ .then_determiner()
+ .then_whitespace()
+ .then(|t: &Token, _source: &[char]| t.kind.is_adjective() && t.kind.is_noun())
+ .then_whitespace()
+ .then_noun(),
+ )
+ }
+
+ thread_local! {static ARTICLE_PATTERN: Lrc<SequencePattern> = Document::uncached_article_pattern()}
+
+ /// When a word that is either an adjective or a noun is sandwiched between an article and a noun,
+ /// it definitely is not a noun.
+ fn articles_imply_nouns(&mut self) {
+ let pattern = Self::ELLIPSIS_PATTERN.with(|v| v.clone());
+
+ for m in pattern.find_all_matches_in_doc(self) {
+ if let TokenKind::Word(Some(metadata)) = &mut self.tokens[m.start + 2].kind {
+ metadata.noun = None;
+ metadata.verb = None;
+ }
+ }
+ }
+
/// Convert all sets of newlines greater than 2 to paragraph breaks.
fn newlines_to_breaks(&mut self) {
for token in &mut self.tokens {
diff --cc harper-core/src/linting/confident.rs
index 000000000,9eeabf573..c4cb8aff2
mode 000000,100644..100644
--- a/harper-core/src/linting/confident.rs
+++ b/harper-core/src/linting/confident.rs
@@@ -1,0 -1,163 +1,163 @@@
+ use crate::{
+ Token,
+ char_string::char_string,
+ patterns::{AnyCapitalization, OwnedPatternExt, Pattern, SequencePattern},
+ };
+
+ use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+ pub struct Confident {
+ pattern: Box<dyn Pattern>,
+ }
+
+ impl Default for Confident {
+ fn default() -> Self {
+ let pattern = SequencePattern::default()
+ .then(
- (|tok: &Token, _source: &[char]| tok.kind.is_verb() || tok.kind.is_article())
++ (|tok: &Token, _source: &[char]| tok.kind.is_verb() || tok.kind.is_determiner())
+ .or(Box::new(AnyCapitalization::new(char_string!("very")))),
+ )
+ .then_whitespace()
+ .t_aco("confidant");
+
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+ }
+
+ impl PatternLinter for Confident {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
+ let span = matched_tokens.last()?.span;
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::ReplaceWith("confident".chars().collect())],
+ message: "Use the adjective.".to_owned(),
+ priority: 127,
+ })
+ }
+
+ fn description(&self) -> &'static str {
+ "This linter detects instances where the noun `confidant` is incorrectly used in place of the adjective `confident`. `Confidant` refers to a trusted person, whereas `confident` describes certainty or self-assurance. The rule suggests replacing `confidant` with `confident` when used in an adjectival context."
+ }
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::Confident;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ #[test]
+ fn describing_person_incorrect() {
+ assert_suggestion_result(
+ "She felt confidant about her presentation.",
+ Confident::default(),
+ "She felt confident about her presentation.",
+ );
+ }
+
+ #[test]
+ fn describing_person_correct() {
+ assert_lint_count(
+ "She felt confident about her presentation.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn certainty_incorrect() {
+ assert_suggestion_result(
+ "I am confidant the test results are accurate.",
+ Confident::default(),
+ "I am confident the test results are accurate.",
+ );
+ }
+
+ #[test]
+ fn certainty_correct() {
+ assert_lint_count(
+ "I am confident the test results are accurate.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn demeanor_incorrect() {
+ assert_suggestion_result(
+ "He walked to the stage with a confidant stride.",
+ Confident::default(),
+ "He walked to the stage with a confident stride.",
+ );
+ }
+
+ #[test]
+ fn demeanor_correct() {
+ assert_lint_count(
+ "He walked to the stage with a confident stride.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn professional_incorrect() {
+ assert_suggestion_result(
+ "You should sound confidant during job interviews.",
+ Confident::default(),
+ "You should sound confident during job interviews.",
+ );
+ }
+
+ #[test]
+ fn professional_correct() {
+ assert_lint_count(
+ "You should sound confident during job interviews.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn assured_tone_incorrect() {
+ assert_suggestion_result(
+ "Present your argument in a confidant, persuasive manner.",
+ Confident::default(),
+ "Present your argument in a confident, persuasive manner.",
+ );
+ }
+
+ #[test]
+ fn assured_tone_correct() {
+ assert_lint_count(
+ "Present your argument in a confident, persuasive manner.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn extra_text_between() {
+ assert_suggestion_result(
+ "She felt very confidant about her presentation.",
+ Confident::default(),
+ "She felt very confident about her presentation.",
+ );
+ }
+
+ #[test]
+ fn linking_verb_was_confidant() {
+ assert_suggestion_result(
+ "She was confidant about her presentation.",
+ Confident::default(),
+ "She was confident about her presentation.",
+ );
+ }
+ }
diff --cc harper-core/src/linting/modal_of.rs
index 000000000,50336a418..7281efa55
mode 000000,100644..100644
--- a/harper-core/src/linting/modal_of.rs
+++ b/harper-core/src/linting/modal_of.rs
@@@ -1,0 -1,296 +1,296 @@@
+ use crate::{
+ Lrc, Token, TokenStringExt,
+ patterns::{EitherPattern, Pattern, SequencePattern, WordSet},
+ };
+
+ use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+ pub struct ModalOf {
+ pattern: Box<dyn Pattern>,
+ }
+
+ impl Default for ModalOf {
+ fn default() -> Self {
+ // Note 1. "shan't of" is plausible but very unlikely
+ // Note 2. "had of" has trickier false positives and is less common anyway
+ // "The only other report we've had of this kind of problem ..."
+ // "The code I had of this used to work fine ..."
+ let modals = ["could", "might", "must", "should", "would"];
+ let mut words = WordSet::new(&modals);
+ modals.iter().for_each(|word| {
+ words.add(&format!("{}n't", word));
+ });
+
+ let modal_of = Lrc::new(
+ SequencePattern::default()
+ .then(words)
+ .then_whitespace()
+ .then_exact_word("of"),
+ );
+
+ let ws_course = Lrc::new(
+ SequencePattern::default()
+ .then_whitespace()
+ .then_exact_word("course"),
+ );
+
+ let modal_of_course = Lrc::new(
+ SequencePattern::default()
+ .then(modal_of.clone())
+ .then(ws_course.clone()),
+ );
+
+ let anyword_might_of = Lrc::new(
+ SequencePattern::default()
+ .then_any_word()
+ .then_whitespace()
+ .then_exact_word("might")
+ .then_whitespace()
+ .then_exact_word("of"),
+ );
+
+ let anyword_might_of_course = Lrc::new(
+ SequencePattern::default()
+ .then(anyword_might_of.clone())
+ .then(ws_course.clone()),
+ );
+
+ Self {
+ pattern: Box::new(EitherPattern::new(vec![
+ Box::new(anyword_might_of_course),
+ Box::new(modal_of_course),
+ Box::new(anyword_might_of),
+ Box::new(modal_of),
+ ])),
+ }
+ }
+ }
+
+ impl PatternLinter for ModalOf {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_toks: &[Token], source_chars: &[char]) -> Option<Lint> {
+ let modal_index = match matched_toks.len() {
+ // Without context, always an error from the start
+ 3 => 0,
+ 5 => {
+ // False positives: modal _ of _ course / adj. _ might _ of / art. _ might _ of
+ let w3_text = matched_toks
+ .last()
+ .unwrap()
+ .span
+ .get_content(source_chars)
+ .iter()
+ .collect::<String>();
+ if w3_text.as_str() != "of" {
+ return None;
+ }
+ let w1_kind = matched_toks.first().unwrap().kind;
+ // the might of something, great might of something
- if w1_kind.is_adjective() || w1_kind.is_article() {
++ if w1_kind.is_adjective() || w1_kind.is_determiner() {
+ return None;
+ }
+ // not a false positive, skip context before
+ 2
+ }
+ // False positive: <word> _ might _ of _ course
+ 7 => return None,
+ _ => unreachable!(),
+ };
+
+ let span_modal_of = matched_toks[modal_index..modal_index + 3].span().unwrap();
+
+ let modal_have = format!(
+ "{} have",
+ matched_toks[modal_index]
+ .span
+ .get_content_string(source_chars)
+ )
+ .chars()
+ .collect();
+
+ Some(Lint {
+ span: span_modal_of,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::replace_with_match_case(
+ modal_have,
+ span_modal_of.get_content(source_chars),
+ )],
+ message: "Use `have` rather than `of` here.".to_string(),
+ priority: 126,
+ })
+ }
+
+ fn description(&self) -> &'static str {
+ "Detects `of` mistakenly used with `would`, `could`, `should`, etc."
+ }
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::ModalOf;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ // atomic unit tests
+
+ #[test]
+ fn test_lowercase() {
+ assert_suggestion_result("could of", ModalOf::default(), "could have");
+ }
+
+ #[test]
+ fn test_negative() {
+ assert_suggestion_result("mightn't of", ModalOf::default(), "mightn't have");
+ }
+
+ #[test]
+ fn test_uppercase_negative() {
+ assert_suggestion_result("Mustn't of", ModalOf::default(), "Mustn't have");
+ }
+
+ #[test]
+ fn test_false_positive_of_course() {
+ assert_lint_count("should of course", ModalOf::default(), 0);
+ }
+
+ #[test]
+ fn test_false_positive_the_might_of() {
+ assert_lint_count("the might of", ModalOf::default(), 0);
+ }
+
+ #[test]
+ fn test_false_positive_great_might_of() {
+ assert_lint_count("great might of", ModalOf::default(), 0);
+ }
+
+ #[test]
+ fn test_false_positive_capital_negative() {
+ assert_lint_count("Wouldn't of course", ModalOf::default(), 0);
+ }
+
+ // real-world tests
+
+ #[test]
+ fn test_buggy_implementation() {
+ assert_lint_count(
+ "... could of just been a buggy implementation",
+ ModalOf::default(),
+ 1,
+ );
+ }
+
+ #[test]
+ fn test_missed_one() {
+ assert_lint_count(
+ "We already have a function ... that nedb can understand so we might of missed one.",
+ ModalOf::default(),
+ 1,
+ );
+ }
+
+ #[test]
+ fn test_user_option() {
+ assert_lint_count(
+ "im more likely to believe you might of left in the 'user' option",
+ ModalOf::default(),
+ 1,
+ );
+ }
+
+ #[test]
+ fn catches_must_of() {
+ assert_suggestion_result(
+ "Ah I must of missed that part.",
+ ModalOf::default(),
+ "Ah I must have missed that part.",
+ );
+ }
+
+ #[test]
+ fn catches_should_of() {
+ assert_lint_count(
+ "Yeah I should of just mentioned it should of been a for of.",
+ ModalOf::default(),
+ 2,
+ );
+ }
+
+ #[test]
+ fn catches_would_of() {
+ assert_suggestion_result(
+ "now this issue would of caused hundreds of thousands of extra lines",
+ ModalOf::default(),
+ "now this issue would have caused hundreds of thousands of extra lines",
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_you_could_of_course() {
+ assert_lint_count(
+ "You could of course explicit the else with each possibility",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_compiler_could_of_course() {
+ assert_lint_count(
+ "The compiler could of course detect this too",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_might_of_course_be() {
+ assert_lint_count(
+ "There might of course be other places where not implementing the IMemberSource might break ...",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_not_a_must_of_course() {
+ assert_lint_count(
+ "Not a must of course if the convention should be .ts",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_must_of_course_also() {
+ assert_lint_count(
+ "the schedular must of course also have run through",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_should_of_course_not() {
+ assert_lint_count(
+ "not being local should of course not be supported",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_would_of_course_just() {
+ assert_lint_count(
+ "I would of course just test this by compiling with MATX_MULTI_GPU=ON",
+ ModalOf::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn doesnt_catch_to_take_on_the_full_might_of_nato() {
+ assert_lint_count("To take on the full might of NATO.", ModalOf::default(), 0);
+ }
+ }
diff --cc harper-core/src/linting/oxford_comma.rs
index 7e7db0a41,7a8589234..ec2769d30
--- a/harper-core/src/linting/oxford_comma.rs
+++ b/harper-core/src/linting/oxford_comma.rs
@@@ -1,35 -1,44 +1,45 @@@
use crate::{
- Document, Token, TokenStringExt,
- patterns::{NominalPhrase, Pattern, SequencePattern, WordSet},
+ Lrc, Token, TokenStringExt,
+ linting::Linter,
+ patterns::{OwnedPatternExt, Pattern, SequencePattern, WordSet},
};
- use super::{Lint, LintKind, Linter, Suggestion};
+ use super::{super::Lint, LintKind, Suggestion};
pub struct OxfordComma {
- pattern: SequencePattern,
+ pattern: Box<dyn Pattern>,
}
- impl OxfordComma {
- pub fn new() -> Self {
- Self {
- pattern: {
- let this = {
- let this = SequencePattern::default().then_one_or_more(Box::new(
- SequencePattern::default()
- .then(NominalPhrase)
- .then_comma()
- .then_whitespace(),
- ));
- this.then(NominalPhrase)
- }
+ impl Default for OxfordComma {
+ fn default() -> Self {
+ let item = Lrc::new(
+ SequencePattern::default()
- .then_article()
++ .then_determiner()
.then_whitespace()
- .then(WordSet::new(&["and", "or", "nor"]))
- .then_whitespace();
- this.then(NominalPhrase)
- },
- .then_noun()
- .or(Box::new(SequencePattern::default().then_noun())),
++ .then_nominal()
++ .or(Box::new(SequencePattern::default().then_nominal())),
+ );
++
+ let item_chunk = SequencePattern::default()
+ .then(item.clone())
+ .then_comma()
+ .then_whitespace();
+
+ let pattern = SequencePattern::default()
+ .then_one_or_more(item_chunk)
+ .then(item.clone())
+ .then_whitespace()
+ .then(WordSet::new(&["and", "or", "nor"]))
+ .then_whitespace()
+ .then(item.clone());
+
+ Self {
+ pattern: Box::new(pattern),
}
}
+ }
+ impl OxfordComma {
fn match_to_lint(&self, matched_toks: &[Token], _source: &[char]) -> Option<Lint> {
let conj_index = matched_toks.last_conjunction_index()?;
let offender = matched_toks[conj_index - 2];
diff --cc harper-core/src/linting/pronoun_contraction/should_contract.rs
index af480636d,90639a6bc..f4127699e
--- a/harper-core/src/linting/pronoun_contraction/should_contract.rs
+++ b/harper-core/src/linting/pronoun_contraction/should_contract.rs
@@@ -17,9 -17,9 +17,9 @@@ impl Default for ShouldContract
SequencePattern::default()
.then(WordSet::new(&["your", "were"]))
.then_whitespace()
- .t_aco("the")
- .then_article()
++ .then_determiner()
.then_whitespace()
- .then_noun(),
+ .then_adjective(),
),
}
}
diff --cc harper-core/src/patterns/sequence_pattern.rs
index 1355af790,654d1e1ec..776ac7d9a
--- a/harper-core/src/patterns/sequence_pattern.rs
+++ b/harper-core/src/patterns/sequence_pattern.rs
@@@ -83,8 -82,9 +83,9 @@@ impl SequencePattern
gen_then_from_is!(adjective);
gen_then_from_is!(apostrophe);
gen_then_from_is!(hyphen);
- gen_then_from_is!(article);
+ gen_then_from_is!(determiner);
gen_then_from_is!(proper_noun);
+ gen_then_from_is!(preposition);
pub fn then_indefinite_article(self) -> Self {
self.then(IndefiniteArticle::default())
diff --cc harper-core/src/word_metadata.rs
index 246de209a,8922a17be..519e35cc2
--- a/harper-core/src/word_metadata.rs
+++ b/harper-core/src/word_metadata.rs
@@@ -104,87 -102,13 +104,87 @@@ impl WordMetadata
}
generate_metadata_queries!(
- noun has proper, plural, possessive, pronoun.
+ noun has proper, plural, possessive.
+ pronoun has plural, possessive.
- verb has linking.
+ verb has linking, auxiliary.
conjunction has.
adjective has.
adverb has
);
- /// Checks if the word is definitely a nominalpro.
++ /// Checks if the word is definitely nominal.
+ pub fn is_nominal(&self) -> bool {
+ self.noun.is_some() || self.pronoun.is_some()
+ }
+
+ /// Checks if the word is definitely a nominal and more specifically is labeled as (a) plural.
+ pub fn is_plural_nominal(&self) -> bool {
+ matches!(
+ self.noun,
+ Some(NounData {
+ is_plural: Some(true),
+ ..
+ })
+ ) || matches!(
+ self.pronoun,
+ Some(PronounData {
+ is_plural: Some(true),
+ ..
+ })
+ )
+ }
+
+ /// Checks if the word is definitely a nominal and more specifically is labeled as (a) possessive.
+ pub fn is_possessive_nominal(&self) -> bool {
+ matches!(
+ self.noun,
+ Some(NounData {
+ is_possessive: Some(true),
+ ..
+ })
+ ) || matches!(
+ self.pronoun,
+ Some(PronounData {
+ is_possessive: Some(true),
+ ..
+ })
+ )
+ }
+
+ /// Checks if the word is definitely a nominal and more specifically is labeled as __not__ (a) plural.
+ pub fn is_not_plural_nominal(&self) -> bool {
+ matches!(
+ self.noun,
+ Some(NounData {
+ is_plural: Some(false),
+ ..
+ })
+ ) && matches!(
+ self.pronoun,
+ Some(PronounData {
+ is_plural: Some(false),
+ ..
+ })
+ )
+ }
+
+ /// Checks if the word is definitely a nominal and more specifically is labeled as __not__ (a) possessive.
+ pub fn is_not_possessive_nominal(&self) -> bool {
+ matches!(
+ self.noun,
+ Some(NounData {
+ is_possessive: Some(false),
+ ..
+ })
+ ) && matches!(
+ self.pronoun,
+ Some(PronounData {
+ is_possessive: Some(false),
+ ..
+ })
+ )
+ }
+
/// Checks whether a word is _definitely_ a swear.
pub fn is_swear(&self) -> bool {
matches!(self.swear, Some(true))