Descriptions

The galactic.descriptions module.

It defines essential classes for representing descriptions:

And classes for representing predicates:

  • Predicate for representing predicates

  • Equal for predicates whose calls to an individual will be retrieved by a equality with a value

  • Member for predicates whose calls to an individual will be retrieved by a membership test access

  • Absurd for predicates whose calls to an individual will be always false

  • Tautology 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 cache

Get the cache property.

Returns

The cache property.

Return type

bool

clear()None

Clear the cache.

property components

Get the inner characteristics.

Returns

The inner characteristics.

Return type

Sequence[Characteristic]

property explanation

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]

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

Iterator[Predicate]

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

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

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

Iterator[Predicate]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]

property space

Get the space property.

Returns

The space property

Return type

Sequence[Characteristic[Any]]

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 cache

Get the cache property.

Returns

The cache property.

Return type

bool

property characteristic

Get the inner characteristic.

Returns

The inner characteristic.

Return type

Characteristic

clear()None

Clear the cache.

property components

Get the inner characteristics.

Returns

The inner characteristics.

Return type

Sequence[Characteristic]

property explanation

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]

property name

Get the value.

Returns

The value.

Return type

Hashable

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 cache

Get the cache property.

Returns

The cache property.

Return type

bool

property characteristic

Get the inner characteristic.

Returns

The inner characteristic.

Return type

Characteristic

clear()None

Clear the cache.

property components

Get the inner characteristics.

Returns

The inner characteristics.

Return type

Sequence[Characteristic]

property data

Get the value.

Returns

The value.

Return type

Hashable

property explanation

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]

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 cache

Get the cache property.

Returns

The cache property.

Return type

bool

clear()None

Clear the cache.

property components

Get the inner characteristics.

Returns

The inner characteristics.

Return type

Sequence[Characteristic]

property explanation

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]

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 cache

Get the cache property.

Returns

The cache property.

Return type

bool

clear()None

Clear the cache.

property components

Get the inner characteristics.

Returns

The inner characteristics.

Return type

Sequence[Characteristic]

property explanation

Get the explanation.

Returns

The strategy explanation.

Return type

Optional[str]

property label

Get the label.

Returns

The strategy label.

Return type

Optional[str]