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: 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.

Parameters:

individual – Any python object

Returns:

A boolean value or None

Return type:

bool, optional

__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 cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

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:

Iterator[Predicate]

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

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

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:

Iterator[Predicate]

property label: str

Get the label.

Returns:

The label.

Return type:

str

property space: Sequence[Characteristic]

Get the space.

Returns:

The space property

Return type:

Sequence[Characteristic[Any]]

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 cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

property characteristic: Optional[Characteristic]

Get the inner characteristic.

Returns:

The inner characteristic.

Return type:

Characteristic, optional

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

property name: Hashable

Get the value.

Returns:

The value.

Return type:

Hashable

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
__call__(individual: Any) Optional[Any]

Make this predicate callable.

Keyword Arguments:

individual (Any, optional) – Any python object

Returns:

True

if the individual has the False value for the embedded characteristics

False

otherwise

Return type:

bool, optional

__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 cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

property characteristic: Optional[Characteristic]

Get the characteristic.

Returns:

The characteristic.

Return type:

Characteristic, optional

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

property data: Hashable

Get the data.

Returns:

The data.

Return type:

Hashable

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

class Absurd(*components: Characteristic, cache: bool = True, **kwargs: Any)

The Absurd class represent the absurd class. It is always false.

__call__(individual: Any) Optional[Any]

Make this predicate callable.

Keyword Arguments:

individual – Any python object

Returns:

The False value.

Return type:

bool, optional

__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 cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

class Tautology(*components: Characteristic, cache: bool = True, **kwargs: Any)

The Tautology class represent the tautology class. It is always true.

__call__(individual: Any) Optional[Any]

Make this predicate callable.

Keyword Arguments:

individual – Any python object

Returns:

The True value.

Return type:

bool, optional

__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 cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str