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
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
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
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
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
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
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
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
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
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
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
-
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
characteristic
¶ Get the inner characteristic.
- Returns
The inner characteristic.
- Return type
-
property
components
¶ Get the inner characteristics.
- Returns
The inner characteristics.
- Return type
-
property
end
¶ Get the end property.
- Returns
The end property.
- Return type
-
property
explanation
¶ Get the explanation.
- Returns
The strategy explanation.
- Return type
-
property
label
¶ Get the label.
- Returns
The strategy label.
- Return type
-
property
start
¶ Get the start property.
- Returns
The start property.
- Return type
-