Characteristics

The galactic.characteristics module defines characteristics.

  • Characteristic for the superclass of all 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: galactic.characteristics.Characteristic, cache: bool = True, label: Optional[str] = None, explanation: Optional[str] = None)

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

Optional[Any]

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.

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 Named(name: str, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)

The Named class is used to represent named characteristics.

Is is designed for subclassing.

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

Initialise a Named instance.

Parameters
  • characteristic (Characteristic) – The inner characteristic (if any)

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

Keyword Arguments

name – A name (usually a string)

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

Returns

The name.

Return type

str

class Key(name: str, characteristic: Optional[galactic.characteristics.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
__init__(name: str, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)None

Initialise a Named instance.

Parameters
  • characteristic (Characteristic) – The inner characteristic (if any)

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

Keyword Arguments

name – A name (usually a string)

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

Returns

The name.

Return type

str

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

The Property class is used to represent property characteristics.

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

Initialise a Named instance.

Parameters
  • characteristic (Characteristic) – The inner characteristic (if any)

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

Keyword Arguments

name – A name (usually a string)

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

Returns

The name.

Return type

str

class Item(nth: int = 0, characteristic: Optional[galactic.characteristics.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]
__init__(nth: int = 0, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)None

Initialise a Item instance.

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

  • characteristic (Characteristic) – The inner characteristic if any

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 nth

Get the nth value.

Returns

The nth value.

Return type

int

class Slice(start: Optional[int] = None, end: Optional[int] = None, characteristic: Optional[galactic.characteristics.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:]
__init__(start: Optional[int] = None, end: Optional[int] = None, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)None

Initialise a Slice instance.

Keyword Arguments
  • start (int) – The slice start.

  • end (int) – The slice end.

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

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 end

Get the end property.

Returns

The end property.

Return type

Optional[int]

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 start

Get the start property.

Returns

The start property.

Return type

Optional[int]