Descriptions
The galactic.descriptions
module.
It defines essential classes for representing descriptions:
Description
for representing descriptions
And classes for representing predicates:
Predicate
for representing predicatesEqual
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 Predicate(*components: Characteristic, cache: bool = True, **kwargs: Any)
The
Predicate
class represents predicate characteristics.- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- __init__(*components: Characteristic, cache: bool = True, **kwargs: Any) None
Initialise a
Characteristic
instance.- Parameters:
*components (Characteristic) – Inner characteristics (if any).
- Keyword Arguments:
cache (bool) – Is this characteristic is cached?
**kwargs (Any) – Additional keyword arguments.
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- class Description(*space: Characteristic, **kwargs: Any)
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.- abstract __call__(individuals: Iterable[Any]) Iterator[Predicate]
Compute the description of the individuals.
- Parameters:
individuals (
Iterable[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
Iterable[Any]
- __init__(*space: Characteristic, **kwargs: Any) None
Initialise a
Description
class.- Parameters:
*characteristics (Characteristic) – A collection of
Characteristic
.- Keyword Arguments:
**kwargs (Any) – Additional keyword arguments.
- 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
- intersection(*predicates: Predicate) Iterator[Predicate]
Compute the intersection of a collection of predicates.
- Parameters:
*predicates (
Predicate
) – A collection of predicate- Returns:
An iterator of predicates
- Return type:
- property space: Sequence[Characteristic]
Get the space.
- Returns:
The space property
- Return type:
- class Member(name: Hashable, characteristic: Optional[Characteristic] = None, **kwargs: Any)
The
Member
class is used to represent member predicates.Example
>>> from galactic.descriptions import Member >>> a = Member(name="x") >>> print(a) x in ~ >>> a({"x"}) True >>> a({}) False >>>
- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
- Keyword Arguments:
individual – Any python object.
- Returns:
A boolean value.
- Return type:
bool, optional
- __init__(name: Hashable, characteristic: Optional[Characteristic] = None, **kwargs: Any)
Initialise a
Member
instance.- Parameters:
name (:class:Hashable <python:typing.Hashable>`) – Any hashable value.
**kwargs – Used for multi-inheritance
- Keyword Arguments:
characteristic (
Characteristic
, optional) – The inner characteristic (if any).
- property characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- class Equal(data: Hashable, characteristic: Optional[Characteristic] = None, **kwargs: Any)
The
Equal
class represents equality between a characteristic and a value.Example
>>> from galactic.characteristics import Key >>> from galactic.descriptions import Equal >>> a = Equal(data="hello", characteristic=Key(name="x")) >>> print(a) x == hello >>> a(1) >>> a({}) >>> a({"x": "hello"}) True >>> a({"x": "good bye"}) False
- __init__(data: Hashable, characteristic: Optional[Characteristic] = None, **kwargs: Any)
Initialise a
Equal
instance.- Parameters:
data (:class:Hashable <python:typing.Hashable>`) – Any hashable value.
**kwargs – Used for multi-inheritance
- Keyword Arguments:
characteristic (
Characteristic
, optional) – The inner characteristic
- property characteristic: Optional[Characteristic]
Get the characteristic.
- Returns:
The characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- class Absurd(*components: Characteristic, cache: bool = True, **kwargs: Any)
The
Absurd
class represent the absurd class. It is always false.- __init__(*components: Characteristic, cache: bool = True, **kwargs: Any) None
Initialise a
Characteristic
instance.- Parameters:
*components (Characteristic) – Inner characteristics (if any).
- Keyword Arguments:
cache (bool) – Is this characteristic is cached?
**kwargs (Any) – Additional keyword arguments.
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- class Tautology(*components: Characteristic, cache: bool = True, **kwargs: Any)
The
Tautology
class represent the tautology class. It is always true.- __init__(*components: Characteristic, cache: bool = True, **kwargs: Any) None
Initialise a
Characteristic
instance.- Parameters:
*components (Characteristic) – Inner characteristics (if any).
- Keyword Arguments:
cache (bool) – Is this characteristic is cached?
**kwargs (Any) – Additional keyword arguments.
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type: