Categories¶
Category types for categorial grammars: atomic, slash, product, unit,
and modal categories, plus the finite CategorySystem used by chart
parsers.
The category types form the free algebra generated by atoms and type
constructors. CategorySystem.from_generators() enumerates this
algebra to a specified depth, producing finite category inventories for
CCG, Lambek, multimodal TLG, and custom rule systems.
categories
¶
Category types for categorial grammars.
Provides the free algebra of grammatical categories generated by atoms and type constructors. This is the type system underlying chart parsers for CCG, the Lambek calculus, multimodal type-logical grammar, and any bespoke formalism assembled from biclosed monoidal primitives.
Atomic categories
AtomicCategory(name="S") — a basic category like S, NP, N, PP.
Slash categories (internal homs)
SlashCategory(result=R, argument=A, direction="/") — right residual: R/A
SlashCategory(result=R, argument=A, direction="\") — left residual: R\A
Product categories (tensor product)
ProductCategory(left=L, right=R) — tensor: L ⊗ R
Unit category (monoidal unit)
UnitCategory() — the monoidal unit I satisfying I ⊗ A ≅ A ≅ A ⊗ I.
Modal categories (unary type constructors)
ModalCategory(modality="◇", inner=A) — a modality applied to a category.
Category systems
A CategorySystem manages a finite inventory of categories
with integer indices, supporting lookup and enumeration.
Category
¶
Bases: TaggedUnion
Sum of grammatical category kinds.
Variants subclass this root and pin kind to a literal value;
Category.model_validate dispatches on that discriminator.
SlashCategory
¶
Bases: Category
A complex category formed by a slash operator.
result/argument (forward): seeks argument on the right.
result\argument (backward): seeks argument on the left.
These are the internal homs of a biclosed monoidal category:
/ is the right residual and \ is the left residual.
ProductCategory
¶
Bases: Category
A product category (tensor product) for type-logical grammar.
Represents A ⊗ B in the Lambek calculus.
UnitCategory
¶
ModalCategory
¶
Bases: Category
A modal category: a unary type constructor applied to a category.
Represents modalities like ◇A (diamond) and □A (box) used in multimodal type-logical grammar (Moortgat 1997). Arbitrary named modalities are supported.
CategorySystem
¶
CategorySystem(categories: list[Category] | None = None)
A finite inventory of grammatical categories with integer indices.
Manages the mapping between Category objects and their integer
indices, used by chart parsers.
| PARAMETER | DESCRIPTION |
|---|---|
categories
|
The initial category inventory.
TYPE:
|
Source code in src/quivers/stochastic/categories.py
264 265 266 267 268 269 | |
from_atoms
classmethod
¶
from_atoms(names: list[str]) -> CategorySystem
Create a category system from atomic category names.
Source code in src/quivers/stochastic/categories.py
271 272 273 274 275 | |
from_atoms_and_slash_depth
classmethod
¶
from_atoms_and_slash_depth(names: list[str], max_depth: int = 1) -> CategorySystem
Create a category system with atomic categories and all slash combinations up to a given depth.
Source code in src/quivers/stochastic/categories.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
from_generators
classmethod
¶
from_generators(atoms: list[str], constructors: list[str] | None = None, max_depth: int = 1) -> CategorySystem
Create a category system from atoms and type constructors.
Built-in constructor names:
"slash"— generates all A/B and A\B"product"— generates all A⊗B"unit"— adds the monoidal unit I"diamond"— generates ◇A for all A"box"— generates □A for all A
Source code in src/quivers/stochastic/categories.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
add
¶
add(cat: Category) -> int
Add a category to the system; return its index.
Source code in src/quivers/stochastic/categories.py
335 336 337 338 339 340 341 342 | |
add_slash
¶
Add a slash category and return its index.
Source code in src/quivers/stochastic/categories.py
344 345 346 347 348 349 350 351 352 | |
__getitem__
¶
Look up by name (str), index (int), or category object.
Source code in src/quivers/stochastic/categories.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
index
¶
index(cat: Category) -> int
Get the integer index of a category.
Source code in src/quivers/stochastic/categories.py
382 383 384 385 386 | |
constructor_name_error
¶
constructor_name_error(name: str) -> str
Return the diagnostic for a residuated constructor name.
The message is shared by every validation site so a name is rejected in the same words whether it is caught when the universe is declared or when it is enumerated.
Source code in src/quivers/stochastic/categories.py
232 233 234 235 236 237 238 239 240 241 242 243 244 | |