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 components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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 components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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 characteristic: Optional[Characteristic]
Get the underlying characteristic.
- Returns:
The underlying characteristic.
- Return type:
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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 characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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
- __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 characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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 characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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]
- __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 characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type:
- 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 characteristic: Optional[Characteristic]
Get the inner characteristic.
- Returns:
The inner characteristic.
- Return type:
Characteristic
, optional
- property components: Sequence[Characteristic]
Get the inner characteristics.
- Returns:
The inner characteristics.
- Return type: