Characteristics

The galactic.characteristics module defines characteristics.

  • Characteristic for the superclass of all characteristics;

  • Imprecise for multi-valued characteristics;

  • MultipleValue for transforming characteristic into multi-valued characteristics;

  • Named for named characteristics;

  • Key for characteristics whose calls to an individual will be retrieved by a key access;

  • Property for characteristics whose calls to an individual will be retrieved by a property access;

  • Item for characteristics whose calls to an individual will be retrieved by a nth access;

  • Slice for characteristics whose calls to an individual will be retrieved by a slice access.

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

The Characteristic class is the super class of all characteristics.

It is designed for subclassing.

A characteristic can be called on an individual. It returns a data of this individual.

__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: 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 Imprecise(*components: Characteristic, cache: bool = True, **kwargs: Any)

The Imprecise class is used to represent multi-valued characteristics.

A call to these characteristics returns an optional collection of values.

__call__(individual: Any) Optional[Any]

Return an optional collection of values from the individual.

Returns:

An optional collection. The None value represents a completely unknown value.

Return type:

Collection[Any], 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 MultipleValue(characteristic: Optional[Characteristic] = None, multiple: bool = False, **kwargs: Any)

The MultipleValue class.

It is used to transform a characteristic info a multi-valued characteristic.

__call__(individual: Any) Optional[Any]

Return an optional collection from the individual.

Returns:

An optional collection. The None value represents a completely unknown value.

Return type:

Collection[Any], optional

__init__(characteristic: Optional[Characteristic] = None, multiple: bool = False, **kwargs: Any) None

Initialise a MultipleValue instance.

Parameters:

characteristic (:class`Characteristic`, optional) – Inner characteristic (if any).

Keyword Arguments:

multiple (bool) – Do characteristic produce multiple values?

property cache: bool

Get the cache property.

Returns:

The cache property.

Return type:

bool

property characteristic: Optional[Characteristic]

Get the underlying characteristic.

Returns:

The underlying characteristic.

Return type:

Characteristic

clear() None

Clear the cache.

property components: Sequence[Characteristic]

Get the inner characteristics.

Returns:

The inner characteristics.

Return type:

Sequence[Characteristic]

classmethod constructor(value: Any) Optional[Any]

Transform a value.

Parameters:

value – The value to transform

Returns:

The transformed value

Return type:

Any, optional

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

Get the multiple property.

Returns:

The multiple property.

Return type:

bool

class Named(name: str, characteristic: Optional[Characteristic] = None, **kwargs: Any)

The Named class is used to represent named characteristics.

Is is designed for subclassing.

__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: str, characteristic: Optional[Characteristic] = None, **kwargs: Any) None

Initialise a Named instance.

Parameters:

name – A name (usually a string)

Keyword Arguments:
  • characteristic (Characteristic, optional) – The inner characteristic (if any)

  • **kwargs – Unused but useful for multi-class inheritance.

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

Get the name.

Returns:

The name.

Return type:

str

class Key(name: str, characteristic: Optional[Characteristic] = None, **kwargs: Any)

The Key class is used to represent key characteristics.

Example

>>> from galactic.characteristics import Key
>>> a = Key(name="x")
>>> print(a)
x
>>> a({"x": 5})
5
>>> a({})
>>> a=Key(name="y", characteristic=Key(name="x"))
>>> print(a)
x[y]
>>> a({"x": {"y": 5}})
5
__call__(individual: Any) Optional[Any]

Make this characteristic callable.

Parameters:

individual (object) – Any python object

Returns:

The individual key using an array access or None if the individual does not have this key.

Return type:

Any, optional

__init__(name: str, characteristic: Optional[Characteristic] = None, **kwargs: Any) None

Initialise a Named instance.

Parameters:

name – A name (usually a string)

Keyword Arguments:
  • characteristic (Characteristic, optional) – The inner characteristic (if any)

  • **kwargs – Unused but useful for multi-class inheritance.

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

Get the name.

Returns:

The name.

Return type:

str

class Property(name: str, characteristic: Optional[Characteristic] = None, **kwargs: Any)

The Property class is used to represent property characteristics.

__call__(individual: Any) Optional[Any]

Make this characteristic callable.

Keyword Arguments:

individual (object) – Any python object

Returns:

The individual property using a property access.

Return type:

Any, optional

__init__(name: str, characteristic: Optional[Characteristic] = None, **kwargs: Any) None

Initialise a Named instance.

Parameters:

name – A name (usually a string)

Keyword Arguments:
  • characteristic (Characteristic, optional) – The inner characteristic (if any)

  • **kwargs – Unused but useful for multi-class inheritance.

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

Get the name.

Returns:

The name.

Return type:

str

class Item(nth: int = 0, characteristic: Optional[Characteristic] = None, **kwargs: Any)

The Item class is used to represent item sequences.

Example

>>> from galactic.characteristics import Item, Key
>>> a = Item(nth=1)
>>> print(a)
~[1]
>>> a([1, 2, 3])
2
>>> a([])
>>> a = Item(nth=1, characteristic=Key(name="a"))
>>> print(a)
a[1]
__call__(individual: Any) Optional[Any]

Make this characteristic callable.

Keyword Arguments:

individual (object) – Any python object

Returns:

The nth individual value using an array access or None if the individual does not have this nth value.

Return type:

Any, optional

__init__(nth: int = 0, characteristic: Optional[Characteristic] = None, **kwargs: Any) None

Initialise a Item instance.

Keyword Arguments:
  • nth (int) – The numbering of the element in the sequence.

  • 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 nth: int

Get the nth value.

Returns:

The nth value.

Return type:

int

class Slice(start: Optional[int] = None, end: Optional[int] = None, characteristic: Optional[Characteristic] = None, **kwargs: Any)

The Slice class is used to represent item slices.

Example

>>> from galactic.characteristics import Slice, Key
>>> a = Slice(start=1)
>>> print(a)
~[1:]
>>> a([1, 2, 3])
[2, 3]
>>> a(None)
>>> a = Slice(start=1, characteristic=Key(name="a"))
>>> print(a)
a[1:]
__call__(individual: Any) Optional[Any]

Make this characteristic callable.

Keyword Arguments:

individual (object) – Any python object

Returns:

The slice from start to end None if the individual does not have this value.

Return type:

Sequence[Any], optional

__init__(start: Optional[int] = None, end: Optional[int] = None, characteristic: Optional[Characteristic] = None, **kwargs: Any) None

Initialise a Slice instance.

Keyword Arguments:
  • start (int, optional) – The slice start.

  • end (int, optional) – The slice end.

  • characteristic (Characteristic, optional) – The inner characteristic (if any).

  • **kwargs – Unused but useful for multi-class inheritance.

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 end: Optional[int]

Get the end property.

Returns:

The end property.

Return type:

int, optional

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 start: Optional[int]

Get the start property.

Returns:

The start property.

Return type:

int, optional