Language packs¶
What a third-party language pack must implement, and how it tells the library what it can do.
LanguagePack and get_pack are importable from denckring and are under the
README's stability promise: a method here keeps its signature and meaning, and a new
one arrives as an optional member a caller reads with getattr.
denckring.get_pack ¶
get_pack(lang: str) -> LanguagePack
Return the installed pack for a language, or raise UnknownLanguage.
Takes a bare str, not Lang, deliberately (ADR 0044): Lang stays a
closed three-member Literal, so this loads a pack registered under any
id — "es", say — without error. Such a pack is loadable but functionally
invisible everywhere a typed catalogue surface (Meta.names,
Meta.definitions, Description.runs_in) is built against Lang instead.
denckring.LanguagePack ¶
Bases: Protocol
Per-language behaviour.
A pack implements every method here, but one whose capability it does not
declare must raise MissingCapability rather than approximate. word_spans,
alphabet, vowels, ascenders and descenders go beyond the original
four-method sketch: violations need character offsets, and the prisoner's
constraint needs glyph shapes.
Constructive, the protocol a procedure with a generator satisfies, is documented
where it is defined: it is not exported from denckring, so it is outside the
promise. describe(...).constructive answers the same question from the stable
surface.
denckring.core.protocol.Constructive ¶
Bases: Protocol
A procedure that can generate, not merely validate.
apply is optional by ADR 0002, so it is not on BaseProcedure. This
protocol is how callers ask whether a given procedure has one, and it
narrows the type at the same time.
seed was an explicit keyword here and is now an ordinary parameter on
SeedParams, carried by the ten procedures that draw. A keyword named in
this signature binds before **params and so can never be validated, which
is what made seed unvalidatable for all 27.
produce joined apply here for the same reason: runtime_checkable
makes isinstance check method presence only, and every
ConstructiveProcedure inherits both from the base class, so the set of
procedures this protocol matches is unchanged by adding the second name.
Capabilities¶
A pack does not declare a language "supported" or not — it declares a capabilities
set, built from string constants defined in denckring.lang.base: TOKENS,
ALPHABET, FOLD_DIACRITICS, LETTER_SHAPES, SYLLABLES, SYLLABLES_HEURISTIC,
SYLLABLES_DICTIONARY, WORDS, NOUNS, GLOSSES, PHONEMES and STRESS. A
procedure, in turn, declares a requires list of the same strings on its catalogue
entry. BaseProcedure.check compares the two before running anything: if the pack's
capabilities do not cover everything the procedure requires, it raises
MissingCapability naming the
procedure, the language and the missing capability, rather than falling back to an
approximation. Adding a language pack is a matter of implementing
LanguagePack and declaring which of these
strings it can honestly back — nothing more.
Word membership and the graded list¶
is_word and graded_words answer different questions, and in English they
disagree on purpose. is_word is the membership oracle of
ADR 0015: WordNet's noun lemmas and CMUdict's
headwords, deliberately broad ("could this be a word"). graded_words is SCOWL's size
classes of ADR 0028, a ranking by commonness. Each
holds words the other lacks: SCOWL has verbs and adjectives neither oracle source
carries (abjure), and also entries that are not words at all (payed and numbest
sit in band 10), so is_word is not widened to cover it. A caller wanting everyday
words should not treat either as that list, but use the curated everyday-words view,
denckring.words(lang, max_band=...) (ADR 0051),
which leaves out the entries a pack lists in word_exclusions().
Neither is a frequency. English packs with denckring-en-data declare
lexicon.frequency and answer word_frequencies(), each graded word's count in a
million sentences of news (ADR 0052);
denckring.words(lang, order="frequency") sorts the everyday view by it.