Descriptions¶
The galactic.descriptions
module defines essential classes for representing
characteristics:
Predicate
for representing predicatesDescription
for representing descriptionsEqual
for predicates whose calls to an individual will be retrieved by a equality with a valueMember
for predicates whose calls to an individual will be retrieved by a membership test accessAbsurd
for predicates whose calls to an individual will be always falseTautology
for predicates whose calls to an individual will be always true
-
class
galactic.descriptions.
Predicate
(*args: Any, description: Optional[Description] = None, **kwargs: Any)¶ Bases:
galactic.characteristics.main.Characteristic
The
Predicate
class is used for characteristics whose call will return a boolean value.
-
class
galactic.descriptions.
Description
(*args: galactic.characteristics.main.Characteristic, **_: Any)¶ Bases:
object
The
Description
class is used to represent description spaces.A description space must have a
__call__()
method able to compute the minimal descriptors for a collection of individuals.-
maximum
: Optional[int] = None¶ The maximum number of characteristics that can reasonably be solved by this description.
-
minimum
: Optional[int] = None¶ The minimum number of characteristics that can reasonably be solved by this description.
-
__init__
(*args: galactic.characteristics.main.Characteristic, **_: Any) → None¶ Initialise a description.
- Parameters
*args (
tuple
) – A collection ofCharacteristic
.- Raises
RuntimeError – If the number or arguments is not between the minimum and the maximum allowed.
TypeError – If an argument is not an instance of
Characteristic
-
static
combine
(predicates: Iterator[galactic.descriptions.main.Predicate]) → Iterator[galactic.descriptions.main.Predicate]¶ Combine an iterator of predicates.
- Parameters
predicates (
Iterator[Predicate]
) – An iterator of predicates- Returns
An iterator of predicates
- Return type
-
intersection
(*predicates: galactic.descriptions.main.Predicate) → Iterator[galactic.descriptions.main.Predicate]¶ Compute the intersection of a collection of predicates for a particular description.
- Parameters
*predicates (
Predicate
) – A collection of predicate- Returns
An iterator of predicates
- Return type
-
abstract
__call__
(individuals: Collection[Any]) → Iterator[galactic.descriptions.main.Predicate]¶ Compute the description of the individuals.
- Keyword Arguments
individuals (
Collection[Any]
) – A collection of individuals- Returns
An iterator over a set of descriptors.
- Return type
- Raises
TypeError – If the argument is not an instance of
Collection[Any]
-
-
class
galactic.descriptions.
Member
(*args: Any, description: Optional[Description] = None, **kwargs: Any)¶ Bases:
galactic.descriptions.main.Predicate
,galactic.characteristics.main.Named
,galactic.characteristics.main.Composite
The
Member
class is used to represent member predicates.Example
>>> from galactic.descriptions import Member >>> a = Member(name="x") >>> print(a) x >>> a({"x"}) True >>> a({}) False >>>
-
class
galactic.descriptions.
Equal
(*args: Any, description: Optional[Description] = None, **kwargs: Any)¶ Bases:
galactic.descriptions.main.Predicate
,galactic.characteristics.main.Composite
,galactic.characteristics.main.Valued
The
Equal
class is used to represent the equality between a characteristic and a value.-
characteristics
¶ The
characteristics
(tuple ofCharacteristic
instances) hold by this instance. This tuple contains only oneCharacteristic
.- Type
Example
>>> from galactic.characteristics import Key >>> from galactic.descriptions import Equal >>> a = Equal(Key(name="x"), data="hello") >>> print(a) x == hello >>> a(1) >>> a({}) >>> a({"x": "hello"}) True >>> a({"x": "good bye"}) False
-