Characteristics
The galactic.characteristics
module defines characteristics.
Characteristic
for the superclass of all characteristicsNamed
for named characteristicsKey
for characteristics whose calls to an individual will be retrieved by akey
accessProperty
for characteristics whose calls to an individual will be retrieved by aproperty
accessItem
for characteristics whose calls to an individual will be retrieved by anth
accessSlice
for characteristics whose calls to an individual will be retrieved by aslice
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:
Any
, optional
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.
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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.
- __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[galactic.characteristics.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 characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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
- __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[galactic.characteristics.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 characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- class Property(name: str, characteristic: Optional[galactic.characteristics.Characteristic] = None, **kwargs: Any)
The
Property
class is used to represent property characteristics.- __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[galactic.characteristics.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 characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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]
- __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__(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
, optional) – The inner characteristic if any
- property characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional
- property label: Optional[str]
Get the label.
- Returns:
The strategy label.
- Return type:
int, optional
- 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:]
- __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__(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, 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 characteristic: Optional[galactic.characteristics.Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[galactic.characteristics.Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- property end: Optional[int]
Get the end property.
- Returns:
The end property.
- Return type:
int, optional
- property explanation: Optional[str]
Get the explanation.
- Returns:
The strategy explanation.
- Return type:
int, optional