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: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None)¶ The
Predicate
class represents predicate characteristics.-
__init__
(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) → None¶ Initialise a
Characteristic
instance.- Parameters
*components – Inner characteristics (if any).
- Keyword Arguments
cache (bool) – Is this characteristic is cached?
label (
Optional[str]
) – An optional label.explanation (
Optional[str]
) – An optional explanation in markdown text.
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
class
Description
(*characteristics: galactic.characteristics.Characteristic, label: Optional[str] = None, explanation: Optional[str] = None)¶ 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[galactic.descriptions.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__
(*characteristics: galactic.characteristics.Characteristic, label: Optional[str] = None, explanation: Optional[str] = None) → None¶ Initialise a
Description
class.- Parameters
*characteristics (Characteristic) – A collection of
Characteristic
.- Keyword Arguments
label (
Optional[str]
) – An optional label.explanation (
Optional[str]
) – An optional explanation in markdown text.
- 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
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
intersection
(*predicates: galactic.descriptions.Predicate) → Iterator[galactic.descriptions.Predicate]¶ Compute the intersection of a collection of predicates.
- Parameters
*predicates (
Predicate
) – A collection of predicate- Returns
An iterator of predicates
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
property
space
¶ Get the space property.
- Returns
The space property
- Return type
-
abstract
-
class
Member
(name: Hashable, characteristic: Optional[galactic.characteristics.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 >>>
-
__init__
(name: Hashable, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)¶ Initialise a
Member
instance.- Parameters
name (:class:Hashable <python:typing.Hashable>`) – Any hashable value.
characteristic (
Characteristic
) – The inner characteristic (if any).**kwargs – Used for multi-inheritance
-
property
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
Characteristic
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
class
Equal
(data: Hashable, characteristic: Optional[galactic.characteristics.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[galactic.characteristics.Characteristic] = None, **kwargs: Any)¶ Initialise a
Equal
instance.- Parameters
data (:class:Hashable <python:typing.Hashable>`) – Any hashable value.
characteristic (
Characteristic
) – The inner characteristic**kwargs – Used for multi-inheritance
-
property
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
Characteristic
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
class
Absurd
(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None)¶ The
Absurd
class represent the absurd class. It is always false.-
__init__
(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) → None¶ Initialise a
Characteristic
instance.- Parameters
*components – Inner characteristics (if any).
- Keyword Arguments
cache (bool) – Is this characteristic is cached?
label (
Optional[str]
) – An optional label.explanation (
Optional[str]
) – An optional explanation in markdown text.
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
class
Tautology
(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None)¶ The
Tautology
class represent the tautology class. It is always true.-
__init__
(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) → None¶ Initialise a
Characteristic
instance.- Parameters
*components – Inner characteristics (if any).
- Keyword Arguments
cache (bool) – Is this characteristic is cached?
label (
Optional[str]
) – An optional label.explanation (
Optional[str]
) – An optional explanation in markdown text.
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-