Skip to content

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

feat: work in progress clarifying affix system

hippietrail12d111ed3ac0
diff --git a/harper-core/affixes.json b/harper-core/affixes.json
index 5ef61d7d6..1fbb2f961 100644
--- a/harper-core/affixes.json
+++ b/harper-core/affixes.json
@@ -2,7 +2,7 @@
"affixes": {
"K": {
"#": "'pro-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -11,12 +11,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"L": {
"#": "'-ment' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -25,12 +25,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"E": {
"#": "'dis-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -39,12 +39,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"Y": {
"#": "'-ly' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -53,12 +53,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"U": {
"#": "'un-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -67,12 +67,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"H": {
"#": "'-ieth' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": false,
"replacements": [
{
@@ -86,12 +86,12 @@
"condition": "[^y]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"T": {
"#": "'-(i)est' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": false,
"replacements": [
{
@@ -115,12 +115,12 @@
"condition": "[^ey]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"R": {
"#": "'-(i)er' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -144,14 +144,14 @@
"condition": "[^ey]"
}
],
- "adds_metadata": {
+ "target_metadata": {
"adjective": {}
},
- "gifts_metadata": {}
+ "base_metadata": {}
},
"C": {
"#": "'de-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -160,12 +160,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"V": {
"#": "'-ive' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": false,
"replacements": [
{
@@ -179,12 +179,12 @@
"condition": "[^e]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"N": {
"#": "nominalization suffixes: -ion, -ication, -en",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -203,12 +203,12 @@
"condition": "[^ey]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"A": {
"#": "'re-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -217,12 +217,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"Z": {
"#": "'-(i)(e)rs' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -246,12 +246,12 @@
"condition": "[^ey]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"P": {
"#": "'-(i)ness' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -270,12 +270,12 @@
"condition": "[^y]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"M": {
"#": "-'s possessive suffix; contraction of 'has' and 'is",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -284,18 +284,18 @@
"condition": "."
}
],
- "adds_metadata": {
+ "target_metadata": {
"noun": {
"is_possessive": true
}
},
- "gifts_metadata": {
+ "base_metadata": {
"noun": {}
}
},
"F": {
"#": "'con-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -304,12 +304,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"B": {
"#": "'-able' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -328,12 +328,12 @@
"condition": "[^aeiou]e"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"S": {
"#": "'-(i)(e)s' plural suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -357,16 +357,16 @@
"condition": "[^sxzhy]"
}
],
- "adds_metadata": {
+ "target_metadata": {
"noun": {
"is_plural": true
}
},
- "gifts_metadata": {}
+ "base_metadata": {}
},
"D": {
"#": "'-(e)d' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -390,16 +390,16 @@
"condition": "[aeiou]y"
}
],
- "adds_metadata": {
+ "target_metadata": {
"kind": {
"kind": "Adjective"
}
},
- "gifts_metadata": {}
+ "base_metadata": {}
},
"G": {
"#": "'-ing' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -413,16 +413,16 @@
"condition": "[^e]"
}
],
- "adds_metadata": {
+ "target_metadata": {
"verb": {},
"noun": null,
"adjective": null
},
- "gifts_metadata": {}
+ "base_metadata": {}
},
"Q": {
"#": "'-ally' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -431,12 +431,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"O": {
"#": "'-ful' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -445,12 +445,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"I": {
"#": "'in-' prefix",
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -459,12 +459,12 @@
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"X": {
"#": "'-ions', '-ications', '-ens' suffixes",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -483,12 +483,12 @@
"condition": "[^ey]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"J": {
"#": "'-ings' suffix",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -502,16 +502,16 @@
"condition": "[^e]"
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
},
"1": {
"#": "singular noun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"noun": {
"is_plural": false
}
@@ -519,11 +519,11 @@
},
"2": {
"#": "proper noun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"noun": {
"is_proper": true
}
@@ -531,11 +531,11 @@
},
"3": {
"#": "linking verb property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"verb": {
"is_linking": true
}
@@ -543,63 +543,63 @@
},
"4": {
"#": "verb property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"verb": {}
}
},
"5": {
"#": "adjective property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"adjective": {}
}
},
"6": {
"#": "swear word property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {
+ "target_metadata": {
"swear": true
},
- "gifts_metadata": {
+ "base_metadata": {
"swear": true
}
},
"7": {
"#": "conjunction property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"conjunction": {}
}
},
"8": {
"#": "pronoun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {}
}
},
"9": {
"#": "plural noun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"noun": {
"is_plural": true
}
@@ -607,71 +607,71 @@
},
"~": {
"#": "common word property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"common": true
}
},
"+": {
"#": "preposition property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"preposition": true
}
},
"-": {
"#": "determiner property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"determiner": true
}
},
"j": {
"#": "adverb property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"adverb": {}
}
},
"s": {
"#": "subject case property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {}
}
},
"o": {
"#": "object case property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {}
}
},
"f": {
"#": "first-person property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {
"is_plural": false
}
@@ -679,51 +679,51 @@
},
"n": {
"#": "second-person property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {}
}
},
"t": {
"#": "third-person property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {}
}
},
"c": {
"#": "comparative property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"adjective": {}
}
},
"u": {
"#": "superlative property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"adjective": {}
}
},
"*": {
"#": "singular third-person pronoun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {
"is_plural": false,
"person": "Third"
@@ -732,11 +732,11 @@
},
":": {
"#": "plural pronoun property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"pronoun": {
"is_plural": true
}
@@ -744,11 +744,11 @@
},
"m": {
"#": "auxiliary verb property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"verb": {
"is_auxiliary": true
}
@@ -756,31 +756,31 @@
},
"<": {
"#": "American property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"dialect": "American"
}
},
"!": {
"#": "GB property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"dialect": "British"
}
},
"@": {
"#": "CA property",
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [],
- "adds_metadata": {},
- "gifts_metadata": {
+ "target_metadata": {},
+ "base_metadata": {
"dialect": "Canadian"
}
}
diff --git a/harper-core/src/spell/rune/attribute_list.rs b/harper-core/src/spell/rune/attribute_list.rs
index 14d199ed9..af7428967 100644
--- a/harper-core/src/spell/rune/attribute_list.rs
+++ b/harper-core/src/spell/rune/attribute_list.rs
@@ -47,17 +47,19 @@ impl AttributeList {
continue;
};
- gifted_metadata.append(&expansion.gifts_metadata);
+ gifted_metadata.append(&expansion.base_metadata);
let mut new_words: HashMap<CharString, WordMetadata> = HashMap::new();
for replacement in &expansion.replacements {
- if let Some(replaced) =
- Self::apply_replacement(replacement, &word.letters, expansion.suffix)
- {
+ if let Some(replaced) = Self::apply_replacement(
+ replacement,
+ &word.letters,
+ expansion.suffix_or_property,
+ ) {
if let Some(val) = new_words.get_mut(&replaced) {
- val.append(&expansion.adds_metadata);
+ val.append(&expansion.target_metadata);
} else {
- new_words.insert(replaced, expansion.adds_metadata.clone());
+ new_words.insert(replaced, expansion.target_metadata.clone());
}
}
}
@@ -69,7 +71,7 @@ impl AttributeList {
let Some(attr_def) = self.affixes.get(attr) else {
continue;
};
- if attr_def.suffix != expansion.suffix {
+ if attr_def.suffix_or_property != expansion.suffix_or_property {
opp_attr.push(*attr);
}
}
diff --git a/harper-core/src/spell/rune/expansion.rs b/harper-core/src/spell/rune/expansion.rs
index 9de030e6e..d81384cdd 100644
--- a/harper-core/src/spell/rune/expansion.rs
+++ b/harper-core/src/spell/rune/expansion.rs
@@ -7,40 +7,41 @@ use crate::WordMetadata;
#[derive(Debug, Clone)]
pub struct Expansion {
/// If `!true`, this is a prefix
- pub suffix: bool,
+ /// But if `true` it may be a prefix but may be a property only
+ pub suffix_or_property: bool,
pub cross_product: bool,
pub replacements: Vec<AffixReplacement>,
/// When the expansion is applied, the resulting word will have this
/// metadata appended to it.
- pub adds_metadata: WordMetadata,
+ pub target_metadata: WordMetadata,
/// When the expansion is applied, the __parent__ word will have this
/// metadata appended to it.
- pub gifts_metadata: WordMetadata,
+ pub base_metadata: WordMetadata,
}
impl Expansion {
pub fn into_human_readable(self) -> HumanReadableExpansion {
HumanReadableExpansion {
- suffix: self.suffix,
+ suffix_or_property: self.suffix_or_property,
cross_product: self.cross_product,
replacements: self
.replacements
.iter()
.map(AffixReplacement::to_human_readable)
.collect(),
- adds_metadata: self.adds_metadata,
- gifts_metadata: self.gifts_metadata,
+ target_metadata: self.target_metadata,
+ base_metadata: self.base_metadata,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HumanReadableExpansion {
- pub suffix: bool,
+ pub suffix_or_property: bool,
pub cross_product: bool,
pub replacements: Vec<HumanReadableAffixReplacement>,
- pub adds_metadata: WordMetadata,
- pub gifts_metadata: WordMetadata,
+ pub target_metadata: WordMetadata,
+ pub base_metadata: WordMetadata,
}
impl HumanReadableExpansion {
@@ -52,11 +53,11 @@ impl HumanReadableExpansion {
}
Ok(Expansion {
- suffix: self.suffix,
+ suffix_or_property: self.suffix_or_property,
cross_product: self.cross_product,
replacements,
- adds_metadata: self.adds_metadata,
- gifts_metadata: self.gifts_metadata,
+ target_metadata: self.target_metadata,
+ base_metadata: self.base_metadata,
})
}
}
diff --git a/harper-core/src/spell/rune/mod.rs b/harper-core/src/spell/rune/mod.rs
index 0a4badbc2..323baf63c 100644
--- a/harper-core/src/spell/rune/mod.rs
+++ b/harper-core/src/spell/rune/mod.rs
@@ -34,7 +34,7 @@ mod tests {
json!({
"affixes": {
"A": {
- "suffix": false,
+ "suffix_or_property": false,
"cross_product": true,
"replacements": [
{
@@ -43,14 +43,14 @@ mod tests {
"condition": "."
}
],
- "adds_metadata": {
+ "target_metadata": {
"kind": null,
"tense": null
},
- "gifts_metadata": {}
+ "base_metadata": {}
},
"B": {
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -64,11 +64,11 @@ mod tests {
"condition": "y"
}
],
- "adds_metadata": {
+ "target_metadata": {
"kind": null,
"tense": null
},
- "gifts_metadata": {}
+ "base_metadata": {}
}
}
})
@@ -151,7 +151,7 @@ mod tests {
&json!({
"affixes": {
"S": {
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -170,17 +170,17 @@ mod tests {
"condition": "[^sxzhy]"
}
],
- "adds_metadata": {
+ "target_metadata": {
"noun": {
"is_plural": true
}
},
- "gifts_metadata": {
+ "base_metadata": {
"noun": {}
}
},
"M": {
- "suffix": true,
+ "suffix_or_property": true,
"cross_product": true,
"replacements": [
{
@@ -189,8 +189,8 @@ mod tests {
"condition": "."
}
],
- "adds_metadata": {},
- "gifts_metadata": {}
+ "target_metadata": {},
+ "base_metadata": {}
}
}
})
diff --git a/packages/web/src/routes/docs/contributors/dictionary/+page.md b/packages/web/src/routes/docs/contributors/dictionary/+page.md
index 19f4e3a38..64d28f658 100644
--- a/packages/web/src/routes/docs/contributors/dictionary/+page.md
+++ b/packages/web/src/routes/docs/contributors/dictionary/+page.md
@@ -19,7 +19,7 @@ In `affixes.json`, this expansion rule looks like this:
{
"L": {
// Denotes that the area of interest is at the _end_ of the base word.
- "suffix": true,
+ "suffix_or_property": true,
// Declare that it is OK to use the result of the expansion with other expansions.
"cross_product": true,
// The actual replacement rules that result in an expansion.