Descriptions

The galactic.descriptions module defines essential classes for representing characteristics:

  • Predicate for representing predicates

  • Description for representing descriptions

  • 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 galactic.descriptions.Predicate(*args: Any, description: Optional[Description] = None, **kwargs: Any)

Bases: galactic.characteristics.main.Characteristic

The Predicate class is used for characteristics whose call will return a boolean value.

class galactic.descriptions.Description(*args: galactic.characteristics.main.Characteristic, **_: Any)

Bases: object

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.

space

A collection of characteristics.

Type

tuple

maximum: Optional[int] = None

The maximum number of characteristics that can reasonably be solved by this description.

minimum: Optional[int] = None

The minimum number of characteristics that can reasonably be solved by this description.

__init__(*args: galactic.characteristics.main.Characteristic, **_: Any)None

Initialise a description.

Parameters

*args (tuple) – A collection of Characteristic.

Raises
static combine(predicates: Iterator[galactic.descriptions.main.Predicate]) → Iterator[galactic.descriptions.main.Predicate]

Combine an iterator of predicates.

Parameters

predicates (Iterator[Predicate]) – An iterator of predicates

Returns

An iterator of predicates

Return type

Iterator[Predicate]

intersection(*predicates: galactic.descriptions.main.Predicate) → Iterator[galactic.descriptions.main.Predicate]

Compute the intersection of a collection of predicates for a particular description.

Parameters

*predicates (Predicate) – A collection of predicate

Returns

An iterator of predicates

Return type

Iterator[Predicate]

abstract __call__(individuals: Collection[Any]) → Iterator[galactic.descriptions.main.Predicate]

Compute the description of the individuals.

Keyword Arguments

individuals (Collection[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 Collection[Any]

class galactic.descriptions.Member(*args: Any, description: Optional[Description] = None, **kwargs: Any)

Bases: galactic.descriptions.main.Predicate, galactic.characteristics.main.Named, galactic.characteristics.main.Composite

The Member class is used to represent member predicates.

name

The name hold by the instance.

Type

str

characteristics

The tuple of Characteristic instances hold by this instance.

Type

tuple

Example

>>> from galactic.descriptions import Member
>>> a = Member(name="x")
>>> print(a)
x
>>> a({"x"})
True
>>> a({})
False
>>>
class galactic.descriptions.Equal(*args: Any, description: Optional[Description] = None, **kwargs: Any)

Bases: galactic.descriptions.main.Predicate, galactic.characteristics.main.Composite, galactic.characteristics.main.Valued

The Equal class is used to represent the equality between a characteristic and a value.

characteristics

The characteristics (tuple of Characteristic instances) hold by this instance. This tuple contains only one Characteristic.

Type

tuple

data

The data hold by the instance.

Type

object

Example

>>> from galactic.characteristics import Key
>>> from galactic.descriptions import Equal
>>> a = Equal(Key(name="x"), data="hello")
>>> print(a)
x == hello
>>> a(1)
>>> a({})
>>> a({"x": "hello"})
True
>>> a({"x": "good bye"})
False
class galactic.descriptions.Absurd(*args: Any, description: Optional[Description] = None, **kwargs: Any)

Bases: galactic.descriptions.main.Predicate

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

class galactic.descriptions.Tautology(*args: Any, description: Optional[Description] = None, **kwargs: Any)

Bases: galactic.descriptions.main.Predicate

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