galactic.algebras.convex.descriptions.category.basic.core#
galactic.algebras.convex.descriptions.category.basic.core module
Define classes for representing category descriptions and predicates.
One class for representing category predicates:
CategoryPredicateclass
One class for representing category descriptions:
CategoryDescriptionclass.
- class CategoryPredicate(**data)#
Bases:
PredicateThe
CategoryPredicateclass is used to represent a category predicate.- Parameters:
space – The space of the predicate, which should be a tuple of one
String,IntegerorBoolean.elements – The elements of the subset.
Example
>>> from galactic.algebras.concept.core import Item >>> from galactic.algebras.convex.characteristics.core import Component, String >>> from galactic.algebras.convex.descriptions.category.basic.core import ( ... CategoryPredicate, ... ) >>> space = (String(components=(Component(),), name="category"),) >>> predicate = CategoryPredicate(space=space, elements=("a", "b", "c")) >>> predicate <galactic.algebras.convex.descriptions.category.basic.core.CategoryPredicate object at 0x...> >>> str(predicate) "category ∈ {'a', 'b', 'c'}" >>> predicate(Item(value="a")) True >>> predicate(Item(value="b")) True >>> predicate(Item(value="d")) False >>> print(predicate(Item(value=None))) None >>> print(predicate(Item())) None
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)#
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- class CategoryDescription(**data)#
Bases:
DescriptionRepresent a categorical description space.
It computes the descriptions of a collection of individuals by computing a category predicate.
- Parameters:
space (tuple[String | Integer | Boolean]) – A tuple of one characteristic representing the space of the description. The characteristic must be an instance of String, Integer or Boolean.
- ALIAS#
The alias of the type in the resource registry.
- Type:
ClassVar[str] = “category.description.Category”
Example
>>> from galactic.algebras.concept.core import Item >>> from galactic.algebras.convex.characteristics.core import Component, String >>> from galactic.algebras.convex.descriptions.category.basic.core import ( ... CategoryDescription, ... ) >>> space = (String(components=(Component(),)),) >>> description = CategoryDescription(space=space) >>> items = [ ... Item(value="a"), ... Item(value="b"), ... Item(value="c"), ... ] >>> [str(attr) for attr in description(items)] ["str(@) ∈ {'a', 'b', 'c'}"] >>> [str(attr) for attr in description([])] ['⊥'] >>> [str(attr) for attr in description([Item()])] []
Configuration
If you want to specify a categorical description in a TOML file, you can use the following syntax:
[components.my_component] "$type" = "core.Component" expr = "value" [characteristics.my_characteristic] "$type" = "core.characteristic.String" components = [ {"$ref" = "components.my_component"} ] name = "my_name" [descriptions.my_description] "$type" = "category.description.Category" space = [ {"$ref" = "characteristics.my_characteristic"}, ]
- Raises:
TypeError – If any element in the space is not an instance of String, Integer or Boolean.