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.- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- Parameters:
individual (object) – Any python object.
- Returns:
The
individual
characteristic.- Return type:
Any
, optional
Hint
If the returned value is
None
, the characteristic is undetermined.- __init__(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) None
Initialise a
Characteristic
instance.
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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:
- 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: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
str, optional
- 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: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
str, optional
- property space: Sequence[galactic.characteristics.Characteristic]
Get the space property.
- Returns:
The space property
- Return type:
- 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 >>>
- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- Parameters:
individual (object) – Any python object.
- Returns:
The
individual
characteristic.- Return type:
Any
, optional
Hint
If the returned value is
None
, the characteristic is undetermined.- __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.
**kwargs – Used for multi-inheritance
- Keyword Arguments:
characteristic (
Characteristic
, optional) – The inner characteristic (if any).
- property characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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
- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- Parameters:
individual (object) – Any python object.
- Returns:
The
individual
characteristic.- Return type:
Any
, optional
Hint
If the returned value is
None
, the characteristic is undetermined.- __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.
**kwargs – Used for multi-inheritance
- Keyword Arguments:
characteristic (
Characteristic
, optional) – The inner characteristic
- property characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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.- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- Parameters:
individual (object) – Any python object.
- Returns:
The
individual
characteristic.- Return type:
Any
, optional
Hint
If the returned value is
None
, the characteristic is undetermined.- __init__(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) None
Initialise a
Characteristic
instance.
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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.- __call__(individual: Any) Optional[Any]
Make this characteristic callable.
This method should be overridden in sub-classes.
- Parameters:
individual (object) – Any python object.
- Returns:
The
individual
characteristic.- Return type:
Any
, optional
Hint
If the returned value is
None
, the characteristic is undetermined.- __init__(*components: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None) None
Initialise a
Characteristic
instance.
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type: