Expand description
English inflection backed by Wiktionary-derived lookup tables with a rule-engine fallback.
§Architecture
Every query follows the same two-tier shape: consult the generated PHF
tables (generated/*_phf.rs, compiled in via include!) for an attested
exception first, and fall back to EnglishCore’s regular rules otherwise.
The tables and the rules are NOT independent: the extractor drops any
candidate the rules already predict, so the tables hold exactly the attested
exceptions and nothing else. Changing a rule in english-core therefore
requires regenerating the tables (cargo xtask refresh-data). Two dump-free
tests partially guard this: the rule_table_sync test below catches a rule
change that makes an existing bare table row redundant, and english-core’s
regular_rules_golden test catches one that breaks the fallback for un-tabled
regular words. Neither is exhaustive — cargo xtask accuracy (with the dump)
is the authoritative check after a rule change.
§Sense-numbered keys
Homograph senses and attested variants are published as _<n>-suffixed
keys (die_2 -> dice). The underscore is unambiguous: the extractor never
admits a lemma containing _, so a trailing _<digits> can only be a sense
suffix — digit-bearing words (mp3, F16, F2) can never collide with one.
Adjacent-digit keys (die2) are deliberately not parsed: they are
indistinguishable from ordinary digit-bearing input.
Key numbers are DETERMINISTIC but NOT immutable. They are assigned by a pure
sort of each lemma’s emitted forms (see extractor::assign): the bare key
goes to the standard sense with the lexicographically-smallest signature (or
is reserved for the rule engine when a regular form is attested), and the
rest number upward. Regenerating from a newer Wiktionary dump can therefore
renumber a lemma’s _<n> keys if its attested forms change — there is no
lockfile or frozen identity. What is stable is the set of forms a lemma
exposes and the rule/table layering below.
§Lookup semantics (invariants shared by English::noun/English::verb/English::adj/English::adverb)
- Case-insensitive convenience: Title-case and ALL-CAPS input hit the
all-lowercase tables with the casing restored on the value; regular-rule
fallbacks get the identical treatment via the internal
rule_with_casehelper, soHOT -> HOTTERexactly asGOOD -> BEST. Mixed case is never guessed at (McDonaldfalls through asMcDonalds). Known acronym homographs of irregular rows are excluded from the case-folded fallback (USinflects by rule, never through theusrow — seeACRONYM_SHADOWED). This is an ergonomic default, not semantic proper-noun detection; callers that care about acronyms, surnames, or house style should normalize casing before/after calling this crate. - Base-lemma agreement: when a
_<n>suffix strips (the word or its base is a table key), EVERY code path treats the input as that base lemma — lookups fall backget_*(word)thenget_*(base)sochild_2inflects exactly likechildinstead of mixing table singulars with rule plurals. - Opaqueness: input that resolves to no key inflects by rule on the whole
string, unchanged (
cat_2->cat_2s).
Structs§
- English
- Entry point for English inflection and morphology.
Enums§
- Animacy
- Animacy marker reserved for higher-level phrase APIs.
- Case
- Pronoun case.
- Degree
- Degree for adjectives and gradable adverbs.
- Form
- Verb form requested from the conjugator.
- Gender
- Pronoun gender for third-person singular forms.
- Number
- Grammatical number.
- Person
- Grammatical person.
- Tense
- Morphological tense realized by finite/simple verb forms.
Functions§
- count
- Inflect a noun according to a numeric count.
- count_
with_ number - Inflect a noun according to a numeric count and keep the number in the output.