Categories¶
Category types for categorial grammars. Provides atomic, slash, product, unit, and modal categories plus a finite CategorySystem for chart parsers.
The category types form the free algebra generated by atoms and type constructors. CategorySystem.from_generators() enumerates this algebra up to a given depth, enabling fully parameterizable grammar construction for any formalism (CCG, Lambek, multimodal TLG, or bespoke).
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
223 224 225 226 227 228 | |
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
230 231 232 233 234 | |
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
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
add
¶
add(cat: Category) -> int
Add a category to the system; return its index.
Source code in src/quivers/stochastic/categories.py
297 298 299 300 301 302 303 304 | |
add_slash
¶
Add a slash category and return its index.
Source code in src/quivers/stochastic/categories.py
306 307 308 309 310 311 312 313 314 | |
__getitem__
¶
Look up by name (str), index (int), or category object.
Source code in src/quivers/stochastic/categories.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
index
¶
index(cat: Category) -> int
Get the integer index of a category.
Source code in src/quivers/stochastic/categories.py
344 345 346 347 348 | |