Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: adding prefixes to dictionary (#2212)
Andrew Dunbarf15778ed2849
diff --git a/harper-core/annotations.json b/harper-core/annotations.jsonindex b72f0eaf3..858710240 100644--- a/harper-core/annotations.json+++ b/harper-core/annotations.json@@ -997,6 +997,14 @@"metadata": {"//": "not yet implemented"}+ },+ "(": {+ "#": "prefix property",+ "metadata": {+ "affix": {+ "is_prefix": true+ }+ }}}}diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dictindex 5ba8e5499..84855c6ba 100644--- a/harper-core/dictionary.dict+++ b/harper-core/dictionary.dict@@ -11157,7 +11157,7 @@ Zworykin/gZyrtec/gZyuganov/gZzz-a/~DP+a/~DP(a.m./aah/NVaardvark/~NSg@@ -12585,7 +12585,7 @@ antagonist/~NSgantagonistic/~JQantagonize/VdSGantarctic/~J-ante/~NSgV+ante/~NSgV(anteater/NgSantebellum/~Jantecedence/Nmg@@ -12620,7 +12620,7 @@ anthropomorphise/V!_anthropomorphism/Nmganthropomorphize/Vanthropomorphous/J-anti/~JNSgP+anti/~JNSgP(antiabortion/Jantiabortionist/NgSantiaircraft/JN@@ -12949,7 +12949,7 @@ arbutus/NgSarc/~NSgVdGarcade/~NgSVarcane/~J-arch/~NgSVGd>J^YpZv+arch/~NgSVGd>J^YpZv(archaeological/~JYarchaeologist/~NSgarchaeology/~Nmg@@ -13508,7 +13508,7 @@ authorized/~JVtTauthorship/~Nmgautism/~Nmgautistic/~JN-auto/~JNgSV+auto/~JNgSV(autobahn/~NSgautobiographer/NSgautobiographic/J@@ -14436,6 +14436,7 @@ bend/~VbG>SNgBZbendability/Nmgbender/~Ngbendy/J^>N+# bene # prefixes that are not also words in their own right don't belong in the dictionarybeneath/~Pbenedictine/~benediction/NwSg@@ -14572,7 +14573,7 @@ bezel/NgSbezier/NgSbf/~Nbhaji/N-bi/~J>NSgZ+bi/~J>NSgZ(biannual/JYNbias/~NgSVGdJbiased/~JVtTU@@ -16892,6 +16893,7 @@ center/~NgJVdGcenterboard/NSgcenterfold/NgScenterpiece/~NgS+# centi # prefixes that are not also words in their own right don't belong in the dictionarycentigrade/JNcentigram/NSgcentiliter/NgS<@@ -17554,6 +17556,7 @@ circularize/VdSGcirculate/~VdSGrcirculation/~NSgrcirculatory/JN+# circum # prefixes that are not also words in their own right don't belong in the dictionarycircumcise/VdSGXncircumcised/JVtTNUcircumcision/~Ng@@ -17913,7 +17916,7 @@ clxviclxviicm/~cnidarian/NgS-co/~NSIdE+co/~NSIdE(coach/~NgSVdGcoachload/NScoachman/N0g@@ -20368,6 +20371,7 @@ dc/~Ndd/~NSdGdded/Kdding/K+# de # prefixes that are not also words in their own right don't belong in the dictionarydeacon/~NgSVdeaconess/NgSdead/~J^Y>NgVXn@@ -20439,6 +20443,7 @@ debtor/~NgSdebugger/NSgdebut/~NgVGddebutante/NSg+# deca # prefixes that are not also words in their own right don't belong in the dictionarydecade/~NgSdecadence/~Nmgdecadency/Nmg@@ -21117,6 +21122,7 @@ dextrose/Nmgdharma/~NwgSdhoti/NSgdhow/NgS+# di # prefixes that are not also words in their own right don't belong in the dictionarydiabetes/~Nmgdiabetic/~JNSgdiabolic/J@@ -21406,7 +21412,7 @@ dirtball/NSdirtily/Rydirtiness/Nmgdirty/~J^>VdSGp-dis/~VNgI+dis/~VNgI(disable/~VdSGJLdisablement/Ngdisambiguate/~VSdGn@@ -22399,6 +22405,7 @@ dynamo/~NSgdynastic/~Jdynasty/~NSgdyno/NSg+# dys # prefixes that are not also words in their own right don't belong in the dictionarydysentery/~Nmgdysfunction/~Nmgdysfunctional/~J@@ -22989,7 +22996,7 @@ emulsification/Nmgemulsifier/~NgSemulsify/Vd>SGnZemulsion/~NwgSV-en/~NSgPI+en/~NSgPI(enable/~Vd>SGZenabler/NgSenact/~VSdGrL@@ -23575,6 +23582,7 @@ etude/NSgetymological/~JYetymologist/NSgetymology/~NwSg+# eu # prefixes that are not also words in their own right don't belong in the dictionaryeucalypti/N9eucalyptus/~N0gSeuchre/NSgVdG@@ -23682,7 +23690,7 @@ evolutionist/NSgevolve/~VdSGewe/~NSg>Zewer/Ng-ex/~NgSVJ+ex/~NgSVJ(exabyte/NgSexacerbate/VGdSnexacerbation/Nwg@@ -24032,7 +24040,7 @@ extortion/~Ng>Zextortionate/JYextortioner/Ngextortionist/NgS-extra/~JNSg+extra/~JNSg(extracellular/~Jextract/~NgSVdGvextraction/~NwSg@@ -25314,7 +25322,7 @@ forceps/N09gforcible/~Jforcibly/~Ryford/~NgSVdGB-fore/~JNgS+fore/~JNgS(forearm/~NSgVGdforebear/NgSVforebode/VGdSNz@@ -28126,7 +28134,7 @@ hesitate/~VdSGnXhesitating/VNYUhesitation/~Nghessian/~N-hetero/~JNSg+hetero/~JNSg(heterodox/Jheterodoxy/Nmgheterogeneity/Ng@@ -28427,7 +28435,7 @@ homily/~NSghominid/NSgJhominoid/NShominy/Ng-homo/~NgSJ+homo/~NgSJ(homoerotic/Jhomogeneity/Nghomogeneous/~JY@@ -28917,6 +28925,7 @@ hymn/~NgSVdGhymnal/~NgSJhymnbook/NSghype/~NmgSVGd>J+# hyper # prefixes that are not also words in their own right don't belong in the dictionaryhyperactive/Jhyperactivity/~Nghyperaggressive/J@@ -29113,6 +29122,7 @@ ignore/~VGdSiguana/~NgSii/~iii/~+# il # prefixes that are not also words in their own right don't belong in the dictionaryilea/Nileitis/Ngileum/Ng@@ -29153,6 +29163,7 @@ illustrative/~JYillustrator/~NSgillustrious/~JYpillustriousness/Nmg+# im # prefixes that are not also words in their own right don't belong in the dictionaryimage/~NwSgVdGimager/NgSimagery/~Nmg@@ -29464,7 +29475,7 @@ impure/~JY^>Vimpurity/~NSgimputation/NSgimpute/VdSGB-in/~PJRrg # removed `4`, verb senses are obsolete, `NS`, noun sense is marginal+in/~PJRrg( # removed `4`, verb senses are obsolete, `NS`, noun sense is marginalinaccuracy/NwgSinaction/~Nmginadequacy/NS@@ -30114,7 +30125,7 @@ intent/~NSgJYpintention/~NgSVintentional/~JYNUintentness/Ng-inter/~VSEL+inter/~VSEL(interact/~VGdSNvinteraction/~NwSginteractive/~JYN@@ -30298,6 +30309,7 @@ intonation/~NSgintoxicant/NSgJintoxicate/VdSGJnintoxication/~Ng+# intra # prefixes that are not also words in their own right don't belong in the dictionaryintracranial/~Jintramural/~JNintramuscular/J@@ -30316,7 +30328,7 @@ intriguer/Ngintriguing/~JYV6Nintrinsic/~JNgSintrinsically/~Ry-intro/~NSgV+intro/~NSgV(introduce/~VGdSrintroduction/~N0grintroductions/~N9@@ -31100,7 +31112,7 @@ killer/~NgJkilling/~JNgVkilljoy/NSgkiln/~NgSVdG-kilo/~NgS+kilo/~NgS(kilobit/NSgkilobyte/NSgkilocoulomb/S@@ -32654,7 +32666,7 @@ mackerel/~NwSgmackinaw/NSgmackintosh/~NgSmacrame/NgV-macro/~JNSg+macro/~JNSg(macroaggregate/Ngmacrobiotic/JSmacrobiotics/Nwg@@ -33383,7 +33395,7 @@ meeting/~NwgSVmeetinghouse/NSgmeetup/NgSmeg/~NSV-mega/~JN+mega/~JN(megabit/NSgmegabucks/Ngmegabyte/NgS@@ -33700,7 +33712,7 @@ mica/~Ngmice/~N9Vmick/~NSJmickey/~NgSV-micro/~JNSgV+micro/~JNSgV(microaggression/NSgmicroarchitecture/NgSmicrobe/NgS@@ -33762,7 +33774,7 @@ microtransaction/NSgmicrovascular/Jmicrowave/~NSgVdGBmicrowaveable/J-mid/~JPN+mid/~JPN(midair/Jmidcentury/Jmidday/~Ng@@ -33864,6 +33876,7 @@ millennial/JNgSmillennium/~NgSmiller/~Ngmillet/~Ng+# milli # prefixes that are not also words in their own right don't belong in the dictionarymilliamp/NgSmilliard/Sgmillibar/NgS@@ -33929,7 +33942,7 @@ minestrone/Nmgminesweeper/NSgmingle/VdGSNmingy/J-mini/~JNgS+mini/~JNgS(miniature/~NgSJVminiaturisation/Ng!_miniaturise/VGdS!_@@ -34001,6 +34014,7 @@ mirthful/JYpmirthfulness/Nmgmirthless/JYmiry/J>^+# mis # prefixes that are not also words in their own right don't belong in the dictionarymisaddress/VdSGmisadventure/NwgSmisaligned/JV@@ -34400,7 +34414,7 @@ monkey/~NgSVdGmonkeyshine/NSgmonkish/Jmonkshood/NSg-mono/~NgJ+mono/~NgJ(monochromatic/~Jmonochrome/~NgSJmonocle/NSgd@@ -34774,7 +34788,7 @@ mullet/~NgSmulligan/~NSgmulligatawny/Ngmullion/NSgVd-multi/~N+multi/~N(multibillion/Jmultibyte/Jmulticellular/J@@ -35273,6 +35287,7 @@ nelson/~NSgnematode/NSgnemeses/N9nemesis/~N0g+# neo # prefixes that are not also words in their own right don't belong in the dictionaryneoclassic/Jneoclassical/~JNneoclassicism/Nmg@@ -35594,7 +35609,7 @@ nomination's/rnominative/~JNSgnominator/~NSgenominee/~NgS-non/~N+non/~N(nonabrasive/JNnonabsorbent/JSgnonacademic/JN@@ -36462,6 +36477,7 @@ omission/~NwgSomit/~VSomitted/~Vomitting/~VN+# omni # prefixes that are not also words in their own right don't belong in the dictionaryomnibus/~NgSJVomnidirectional/Jomnipotence/Nmg@@ -36779,7 +36795,7 @@ ourself/Ia1F # I:pronoun a:personal 1:person .~singular F:reflexive (of tourselves/~Ia1F: # I:pronoun a:personal 1:person :~plural F:reflexiveoust/~VGd>SZouster/~NgSV-out/~PNSgVGd>JRz+out/~PNSgVGd>JRz(outage/NSgoutargue/VGdSoutback/~NgSJV@@ -36942,7 +36958,7 @@ oven/~NgSVovenbird/NSgovenproof/Jovenware/Nmg-over/~JYNgSP+over/~JYNgSP(overabundance/Ngoverabundant/Joverachieve/VGd>SZ@@ -37439,7 +37455,7 @@ pampas/Ngpamper/VdGSNpamphlet/~NgSVpamphleteer/NgSV-pan/~NSgVJ+pan/~NSgVJ(panacea/NSgpanache/Ngpanama/~NgS@@ -37528,7 +37544,7 @@ paprika/~NmgJpapyri/~N9papyrus/~N0gpar/~NSgJ>PVGdZBz-para/~NgSJ+para/~NgSJ(parable/~NgSVJparabola/N0Sgparabolæ/N9@@ -38137,6 +38153,7 @@ peppy/J^>Nppepsin/Ngpeptic/JNgSpeptide/~NS+# per # prefixes that are not also words in their own right don't belong in the dictionaryperadventure/Ngperambulate/VGdSXnperambulation/Nwg@@ -39241,7 +39258,7 @@ polonaise/NSgVpolonium/Nmgpoltergeist/~NgSpoltroon/NSgJ-poly/~NJV+poly/~NJV(polyacrylamide/Npolyamory/NSpolyandrous/J@@ -39448,7 +39465,7 @@ possibility/~NSgpossible/~JNSgpossibly/~R # adverb of probability/certainty/affirmation; modal adverbpossum/~NSgV-post/~NwgSVGd>PZz+post/~NwgSVGd>PZz(postage/~Nmgpostal/~Jpostbag/NgS@@ -40034,7 +40051,7 @@ prizefighter/Ngprizefighting/Ngprizewinner/NgSprizewinning/J-pro/~NSgPJ+pro/~NSgPJ(probabilistic/~Jprobability/~NSgprobable/~JNSg@@ -40316,6 +40333,7 @@ protein/~NwSgprotest/NwgSprotestant/~JNgSprotestation/NwgS+# proto # prefixes that are not also words in their own right don't belong in the dictionaryprotocol/~NwgSVproton/~NSgprotoplasm/Nmg@@ -40389,7 +40407,7 @@ psaltery/NSgpsephologist/NSpsephology/Npseud/NS-pseudo/~NSJ+pseudo/~NSJ(pseudocode/NmgGpseudonym/~NSgpseudonymous/~J@@ -41244,7 +41262,7 @@ razz/NgSVGdrazzmatazz/Ngrcpt/Nrd/~N-re/PNSgvz+re/PNSgvz(reach/~VdGSNgBreachable/~JNUreacquire/VdSG@@ -42130,7 +42148,7 @@ retributive/Jretrieval/~NSgretrieve/~Vd>GSNgZBretriever/Ng-retro/~JNmgS+retro/~JNmgS(retroactive/~JYretrofire/NSVGdJretrofit/~VSNg@@ -43736,7 +43754,7 @@ semaphore/NSgVdGsemblance/NSgrsemen/~Nmgsemester/~NSg-semi/~NgS+semi/~NgS(semiannual/JYNsemiarid/Jsemiautomatic/JNgSQ@@ -46775,7 +46793,7 @@ suasion/NgEsuave/J>Y^Npsuaveness/Ngsuavity/Ng-sub/~NSgVP+sub/~NSgVP(subaltern/JNgSsubaqua/Jsubarctic/~ONJ@@ -47144,7 +47162,7 @@ suntanning/V6suntrap/NSsunup/Ngsup/~V>SNgJZ-super/~JNgV+super/~JNgV(superabundance/NwgSsuperabundant/Jsuperannuate/VGdSn@@ -47283,6 +47301,7 @@ supremacy/~Ngsupreme/~JYVNsupremo/NSsupt/V+# sur # prefixes that are not also words in their own right don't belong in the dictionarysurcease/NSgVdGsurcharge/NSgVdGsurcingle/NSgV@@ -48004,6 +48023,7 @@ teetotalism/Ngteetotaller/NgS!@_tektite/NSgtel/~N+# tele # prefixes that are not also words in their own right don't belong in the dictionarytelecast/~VG>SNgZtelecaster/Ngtelecom/NgS@@ -49152,7 +49172,7 @@ tranquilizer/Ngtranquillise/Vd>SGZ!_tranquilliser/Ng!_tranquillity/Ng!_-trans/~JNVi+trans/~JNVi(transact/VdGStransaction/~NSgtransactional/J@@ -49372,6 +49392,7 @@ tress/NgSVEtrestle/~NgStrews/Ntrey/~NgS+# tri # prefixes that are not also words in their own right don't belong in the dictionarytriad/~NSgtriage/NmgVdtriager/NSg@@ -49900,7 +49921,7 @@ ulterior/Jultimate/~JYNgVultimatum/~NgSultimo/~JN-ultra/~JNSg+ultra/~JNSg(ultraconservative/JNSgultrahigh/Jultraist/NSg@@ -49929,6 +49950,7 @@ umlaut/NgSVump/NSgVGdumpire/~NgSVGdumpteen/H+# un # prefixes that are not also words in their own right don't belong in the dictionaryunabridged/~JNgSunacceptability/Nmgunacceptable/~JN@@ -50026,7 +50048,7 @@ undecided/~JNSgVundefine/VGdSundemonstrative/JYundeniably/Ry-under/~PJN+under/~PJN(underachieve/VGd>SLZunderachiever/Ngunderact/VSdG@@ -50259,6 +50281,7 @@ unhealthy/~J^unhistorical/Junholy/~J^unhurt/J+# uni # prefixes that are not also words in their own right don't belong in the dictionaryunibody/NSgunicameral/~Junicellular/JN@@ -51037,7 +51060,7 @@ vicar/~NSgvicarage/~NSgvicarious/JYpvicariousness/Ng-vice/~NgSVJPe+vice/~NgSVJPe(viced/JVtTvicegerent/NSgJvicennial/JN@@ -53414,7 +53437,7 @@ pentest/VSdGpentester/NSg # penetration testerpentesting/NmgV6postfix/NgSVdG-pre/~PNV # !! please check and comment !! dictionaries only list prefix pre-+pre/~PNV( # !! please check and comment !! dictionaries only list prefix pre-preshared/Jquadtree/NgS # data structurequicksort/NgSVdG # algodiff --git a/harper-core/src/dict_word_metadata.rs b/harper-core/src/dict_word_metadata.rsindex 6f941fcf3..a09cd54c1 100644--- a/harper-core/src/dict_word_metadata.rs+++ b/harper-core/src/dict_word_metadata.rs@@ -18,12 +18,20 @@ use crate::{Document, TokenKind, TokenStringExt};/// having their own lexeme, but "Ivy" and "ivy" sharing the same lexeme.#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Hash)]pub struct DictWordMetadata {+ /// The main parts of speech which have extra data.pub noun: Option<NounData>,pub pronoun: Option<PronounData>,pub verb: Option<VerbData>,pub adjective: Option<AdjectiveData>,pub adverb: Option<AdverbData>,pub conjunction: Option<ConjunctionData>,+ pub determiner: Option<DeterminerData>,+ pub affix: Option<AffixData>,+ /// Parts of speech which don't have extra data.+ /// Whether the word is a [preposition](https://www.merriam-webster.com/dictionary/preposition).+ #[serde(default = "default_false")]+ pub preposition: bool,+ /// Whether the word is an offensive word.pub swear: Option<bool>,/// The dialects this word belongs to./// If no dialects are defined, it can be assumed that the word is@@ -33,11 +41,6 @@ pub struct DictWordMetadata {/// Orthographic information: letter case, spaces, hyphens, etc.#[serde(default = "OrthFlags::empty")]pub orth_info: OrthFlags,- /// Whether the word is a [determiner](https://en.wikipedia.org/wiki/English_determiners).- pub determiner: Option<DeterminerData>,- /// Whether the word is a [preposition](https://www.merriam-webster.com/dictionary/preposition).- #[serde(default = "default_false")]- pub preposition: bool,/// Whether the word is considered especially common.#[serde(default = "default_false")]pub common: bool,@@ -189,11 +192,12 @@ impl DictWordMetadata {adjective: merge!(self.adjective, other.adjective),adverb: merge!(self.adverb, other.adverb),conjunction: merge!(self.conjunction, other.conjunction),+ determiner: merge!(self.determiner, other.determiner),+ affix: merge!(self.affix, other.affix),+ preposition: self.preposition || other.preposition,dialects: self.dialects | other.dialects,orth_info: self.orth_info | other.orth_info,swear: self.swear.or(other.swear),- determiner: merge!(self.determiner, other.determiner),- preposition: self.preposition || other.preposition,common: self.common || other.common,derived_from: self.derived_from.or(other.derived_from),pos_tag: self.pos_tag.or(other.pos_tag),@@ -234,6 +238,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}PROPN => {@@ -259,6 +264,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}PRON => {@@ -272,6 +278,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}VERB => {@@ -293,6 +300,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}AUX => {@@ -314,6 +322,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}ADJ => {@@ -327,6 +336,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}ADV => {@@ -340,6 +350,7 @@ impl DictWordMetadata {self.adjective = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = false;}ADP => {@@ -350,6 +361,7 @@ impl DictWordMetadata {self.adverb = None;self.conjunction = None;self.determiner = None;+ self.affix = None;self.preposition = true;}DET => {@@ -359,6 +371,7 @@ impl DictWordMetadata {self.adjective = None;self.adverb = None;self.conjunction = None;+ self.affix = None;self.preposition = false;self.determiner = Some(DeterminerData::default());}@@ -373,6 +386,7 @@ impl DictWordMetadata {self.adjective = None;self.adverb = None;self.determiner = None;+ self.affix = None;self.preposition = false;}_ => {}@@ -958,6 +972,22 @@ impl ConjunctionData {}}+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, Default)]+pub struct AffixData {+ pub is_prefix: Option<bool>,+ pub is_suffix: Option<bool>,+}++impl AffixData {+ /// Produce a copy of `self` with the known properties of `other` set.+ pub fn or(&self, _other: &Self) -> Self {+ Self {+ is_prefix: self.is_prefix.or(_other.is_prefix),+ is_suffix: self.is_suffix.or(_other.is_suffix),+ }+ }+}+/// A regional dialect.////// Note: these have bit-shifted values so that they can ergonomically integrate with