Skip to content

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

refactor: article→determiner

hippietrail6f98a03bb651
diff --git a/harper-core/affixes.json b/harper-core/affixes.json
index f6874d468..ed037de66 100644
--- a/harper-core/affixes.json
+++ b/harper-core/affixes.json
@@ -631,7 +631,7 @@
"replacements": [],
"adds_metadata": {},
"gifts_metadata": {
- "article": true
+ "determiner": true
}
},
"j": {
diff --git a/harper-core/src/linting/compound_nominals/general_compound_nominals.rs b/harper-core/src/linting/compound_nominals/general_compound_nominals.rs
index d20eb7719..1e41b81cc 100644
--- a/harper-core/src/linting/compound_nominals/general_compound_nominals.rs
+++ b/harper-core/src/linting/compound_nominals/general_compound_nominals.rs
@@ -25,7 +25,7 @@ impl Default for GeneralCompoundNominals {
return false;
};
- meta.article || meta.is_adjective()
+ meta.determiner || meta.is_adjective()
})
.then_whitespace()
.then(|tok: &Token, _: &[char]| {
@@ -33,7 +33,7 @@ impl Default for GeneralCompoundNominals {
return false;
};
- tok.span.len() > 1 && !meta.article && !meta.preposition && !meta.is_adverb()
+ tok.span.len() > 1 && !meta.determiner && !meta.preposition && !meta.is_adverb()
})
.then_whitespace()
.then(|tok: &Token, _: &[char]| {
@@ -41,7 +41,7 @@ impl Default for GeneralCompoundNominals {
return false;
};
- tok.span.len() > 1 && !meta.article && !meta.is_adverb() && !meta.preposition
+ tok.span.len() > 1 && !meta.determiner && !meta.is_adverb() && !meta.preposition
});
let split_pattern = Lrc::new(SplitCompoundWord::new(|meta| {
diff --git a/harper-core/src/linting/hop_hope/to_hop.rs b/harper-core/src/linting/hop_hope/to_hop.rs
index 5a3435a85..192bfb88e 100644
--- a/harper-core/src/linting/hop_hope/to_hop.rs
+++ b/harper-core/src/linting/hop_hope/to_hop.rs
@@ -15,7 +15,7 @@ impl Default for ToHop {
.then_whitespace()
.t_aco("on")
.then_whitespace()
- .then_article()
+ .then_determiner()
.then_whitespace()
.then(WordSet::new(&["airplane", "plane", "bus", "call", "train"]));
diff --git a/harper-core/src/patterns/implies_quantity.rs b/harper-core/src/patterns/implies_quantity.rs
index bbe06926f..fd30ec844 100644
--- a/harper-core/src/patterns/implies_quantity.rs
+++ b/harper-core/src/patterns/implies_quantity.rs
@@ -16,7 +16,7 @@ impl ImpliesQuantity {
match token.kind {
TokenKind::Word(Some(word_metadata)) => {
- if word_metadata.article {
+ if word_metadata.determiner {
return Some(false);
}
diff --git a/harper-core/src/patterns/nominal_phrase.rs b/harper-core/src/patterns/nominal_phrase.rs
index 4e069c982..155368add 100644
--- a/harper-core/src/patterns/nominal_phrase.rs
+++ b/harper-core/src/patterns/nominal_phrase.rs
@@ -14,7 +14,7 @@ impl Pattern for NominalPhrase {
return 0;
};
- if tok.kind.is_adjective() || tok.kind.is_article() {
+ if tok.kind.is_adjective() || tok.kind.is_determiner() {
let Some(next) = tokens.get(cursor + 1) else {
return 0;
};
diff --git a/harper-core/src/patterns/sequence_pattern.rs b/harper-core/src/patterns/sequence_pattern.rs
index 5c599d9b5..7cf1c37a3 100644
--- a/harper-core/src/patterns/sequence_pattern.rs
+++ b/harper-core/src/patterns/sequence_pattern.rs
@@ -21,7 +21,7 @@ use crate::{Token, TokenKind};
///
/// let document = Document::new_markdown_default_curated("This is a test.");
///
-/// let pattern = SequencePattern::default().then_article().then_whitespace().then_nominal();
+/// let pattern = SequencePattern::default().then_determiner().then_whitespace().then_nominal();
/// let matches = pattern.find_all_matches_in_doc(&document);
///
/// // The pattern found that the tokens at indexes 4, 5, and 6 fit the criteria.
@@ -82,7 +82,7 @@ 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_nominal);
pub fn then_indefinite_article(self) -> Self {
diff --git a/harper-core/src/spell/hunspell/expansion.rs b/harper-core/src/spell/hunspell/expansion.rs
index 9de030e6e..00856fa9f 100644
--- a/harper-core/src/spell/hunspell/expansion.rs
+++ b/harper-core/src/spell/hunspell/expansion.rs
@@ -6,6 +6,8 @@ use crate::WordMetadata;
#[derive(Debug, Clone)]
pub struct Expansion {
+ // TODO some attributes only signify a property and neither prefix nor suffix
+ // TODO currently those have the "suffix" field set to true
/// If `!true`, this is a prefix
pub suffix: bool,
pub cross_product: bool,
diff --git a/harper-core/src/title_case.rs b/harper-core/src/title_case.rs
index 9acf1e478..34852c30b 100644
--- a/harper-core/src/title_case.rs
+++ b/harper-core/src/title_case.rs
@@ -96,7 +96,7 @@ fn should_capitalize_token(tok: &Token, source: &[char], dict: &impl Dictionary)
let is_short_preposition = metadata.preposition && tok.span.len() <= 4;
!is_short_preposition
- && !metadata.article
+ && !metadata.determiner
&& !SPECIAL_CONJUNCTIONS.contains(chars_lower.as_ref())
}
_ => true,
diff --git a/harper-core/src/token_kind.rs b/harper-core/src/token_kind.rs
index 1572ba512..9d78d4786 100644
--- a/harper-core/src/token_kind.rs
+++ b/harper-core/src/token_kind.rs
@@ -145,10 +145,13 @@ impl TokenKind {
)
}
- pub fn is_article(&self) -> bool {
+ pub fn is_determiner(&self) -> bool {
matches!(
self,
- TokenKind::Word(Some(WordMetadata { article: true, .. }))
+ TokenKind::Word(Some(WordMetadata {
+ determiner: true,
+ ..
+ }))
)
}
diff --git a/harper-core/src/word_metadata.rs b/harper-core/src/word_metadata.rs
index 48432b0e4..ee26ee037 100644
--- a/harper-core/src/word_metadata.rs
+++ b/harper-core/src/word_metadata.rs
@@ -11,9 +11,9 @@ pub struct WordMetadata {
pub adverb: Option<AdverbData>,
pub conjunction: Option<ConjunctionData>,
pub swear: Option<bool>,
- /// Whether the word is an [article](https://dictionary.cambridge.org/dictionary/english/article).
+ /// Whether the word is a [determiner](https://en.wikipedia.org/wiki/English_determiners).
#[serde(default = "default_false")]
- pub article: bool,
+ pub determiner: bool,
/// Whether the word is a [preposition](https://www.merriam-webster.com/dictionary/preposition).
#[serde(default = "default_false")]
pub preposition: bool,
@@ -35,7 +35,7 @@ macro_rules! generate_metadata_queries {
return true;
}
- [self.article, self.preposition, $(
+ [self.determiner, self.preposition, $(
self.[< is_ $category >](),
)*].iter().map(|b| *b as u8).sum::<u8>() > 1
}
@@ -97,7 +97,7 @@ impl WordMetadata {
adverb: merge!(self.adverb, other.adverb),
conjunction: merge!(self.conjunction, other.conjunction),
swear: self.swear.or(other.swear),
- article: self.article || other.article,
+ determiner: self.determiner || other.determiner,
preposition: self.preposition || other.preposition,
common: self.common || other.common,
}
@@ -124,16 +124,23 @@ 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
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Is, Hash)]
pub enum Tense {
- Past,
- Present,
- Future,
+ // Past,
+ // Present,
+ // Future,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]
pub struct VerbData {
pub is_linking: Option<bool>,
+ // can, could, may, might, must, shall, should, will, would
+ pub is_modal: Option<bool>,
pub tense: Option<Tense>,
}
@@ -142,11 +149,15 @@ impl VerbData {
pub fn or(&self, other: &Self) -> Self {
Self {
is_linking: self.is_linking.or(other.is_linking),
+ is_modal: self.is_modal.or(other.is_modal),
tense: self.tense.or(other.tense),
}
}
}
+// 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)]
pub struct NominalData {
pub is_proper: Option<bool>,
@@ -165,6 +176,7 @@ impl NominalData {
}
}
+// person is a property of pronouns; the verb 'be', plus all verbs reflect 3rd person singular with -s
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Is, Hash)]
pub enum Person {
First,
@@ -172,12 +184,14 @@ pub enum Person {
Third,
}
+// case is a property of pronouns
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Is, Hash)]
pub enum Case {
Subject,
Object,
}
+// TODO for now focused on personal pronouns?
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]
pub struct PronounData {
pub is_plural: Option<bool>,
@@ -198,6 +212,9 @@ impl PronounData {
}
}
+// degree is a property of adjectives: positive is not inflected
+// comparative is inflected with -er or comes after the word "more"
+// superlative is inflected with -est or comes after the word "most"
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Is, Hash)]
pub enum Degree {
Positive,
@@ -205,6 +222,9 @@ pub enum Degree {
Superlative,
}
+// some adjectives are not comparable so don't have -er or -est forms and can't be used with "more" or "most"
+// some adjectives can only be used "attributively" (before a noun); some only predicatively (after "is" etc.)
+// in old grammars words like the articles and determiners are classified as adjectives but behave differently
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]
pub struct AdjectiveData {
pub degree: Option<Degree>,
@@ -219,6 +239,9 @@ impl AdjectiveData {
}
}
+// adverb can be a "junk drawer" category for words which don't fit the other major categories
+// the typical adverbs are "adverbs of mannder", those derived from adjectives in -ly
+// other adverbs (time, place, etc) should probably not be considered adverbs for Harper's purposes
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]
pub struct AdverbData {}