Characteristics¶
The galactic.characteristics
module defines essential classes for representing
characteristics:
Characteristic
for the superclass of all characteristicsValued
for characteristics defined by a dataNamed
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
accessTransformation
for characteristics that hold atransform
operationComposite
for characteristics which contain a collection of otherCharacteristic
instancesConversion
for characteristics that execute atransform
operationSum
for characteristics that execute a sum operationComparison
for characteristics that need astrict
boolean flag used in comparisonSet
for characteristics that contains a set of values
-
class
galactic.characteristics.
Characteristic
(*args, **kwargs)¶ Bases:
typing.Callable
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.
-
galactic.characteristics.
identity
= <galactic.characteristics.Characteristic object>¶ The identity characteristic.
-
class
galactic.characteristics.
Valued
(*args, data=None, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
The
Valued
class is used to hold a data.-
data
¶ The data hold by the instance.
Example
>>> from galactic.characteristics import Valued >>> a = Valued(data=5) >>> print(a) 5 >>> a({}) 5 >>>
-
-
class
galactic.characteristics.
Named
(*args, name=None, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
The
Named
class is used to represent named characteristics. Is is designed for subclassing.-
name
¶ The name hold by the instance. It is used to name
Characteristic
instances.- Type
-
-
class
galactic.characteristics.
Composite
(*args, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
The
Composite
class is used as a container of embeddedCharacteristic
instances. It is designed for subclassing.-
characteristics
¶ The tuple of
Characteristic
instances hold by this instance.- Type
-
__init__
(*args, **kwargs)¶ Initialise a
Composite
instance.- Parameters
*args (
tuple
) – A collection ofCharacteristic
instances**kwargs – Unused but useful for multi-class inheritance.
- Raises
TypeError – If a characteristic is not an instance of
Characteristic
-
-
class
galactic.characteristics.
Key
(characteristic: galactic.characteristics.Characteristic = None, **kwargs)¶ Bases:
galactic.characteristics.Named
,galactic.characteristics.Composite
The
Key
class is used to represent key characteristics.-
characteristics
¶ The tuple of
Characteristic
instances hold by this instance.- Type
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")) >>> a({"x": {"y": 5}}) 5
-
__init__
(characteristic: galactic.characteristics.Characteristic = None, **kwargs)¶ Initialize a
Key
instance.- Keyword Arguments
characteristic (
Characteristic
) – The underlying characteristic.
-
-
class
galactic.characteristics.
Property
(characteristic: galactic.characteristics.Characteristic = None, **kwargs)¶ Bases:
galactic.characteristics.Named
,galactic.characteristics.Composite
The
Property
class is used to represent property characteristics.-
characteristics
¶ The tuple of
Characteristic
instances hold by this instance.- Type
-
__init__
(characteristic: galactic.characteristics.Characteristic = None, **kwargs)¶ Initialize a
Property
instance.- Keyword Arguments
characteristic (
Characteristic
) – The underlying characteristic.
-
-
class
galactic.characteristics.
Transformation
(*args, transform=None, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
The
Transformation
class is used to hold a transform operation. It is designed for subclassing.-
transform
¶ The transform operation hold by the instance. It is used to apply transformation on values.
- Type
-
__init__
(*args, transform=None, **kwargs)¶ Initialise a
Transformation
instance.- Parameters
*args – Unused but useful for multi-class inheritance.
**kwargs – Unused but useful for multi-class inheritance.
- Keyword Arguments
transform – A transform operation.
-
-
class
galactic.characteristics.
Conversion
(characteristic: galactic.characteristics.Characteristic, **kwargs)¶ Bases:
galactic.characteristics.Composite
,galactic.characteristics.Transformation
,galactic.characteristics.Valued
The
Conversion
class is used to convert a characteristic call to a specific type.-
characteristics
¶ The
characteristics
(tuple ofCharacteristic
instances) hold by this instance.- Type
Example
>>> from galactic.characteristics import Conversion, Key >>> a = Conversion(Key(name="x"), transform=float, data="nan") >>> print(a) x >>> a({"x": "5"}) 5.0 >>> a(4) nan
-
__init__
(characteristic: galactic.characteristics.Characteristic, **kwargs)¶ Initialise a
Conversion
instance.- Parameters
characteristic (
Characteristic
) – The embedded characteristics- Keyword Arguments
transform (
Callable
) – A transform operation (inherited fromTransformation.__init__()
).data – Any python object (inherited from
Valued.__init__()
).
-
-
class
galactic.characteristics.
Sum
(*args, start=0, **kwargs)¶ Bases:
galactic.characteristics.Composite
,galactic.characteristics.Transformation
,galactic.characteristics.Valued
The
Sum
class is used to define a sum over otherCharacteristic
instances.-
start
¶ Initial value for the sum. It is used as a beginning for the sum calculus.
-
characteristics
¶ The
characteristics
(tuple ofCharacteristic
instances) hold by this instance.- Type
Example
>>> from galactic.characteristics import Key, Sum >>> s = Sum(Key(name="x"), Key(name="y"), start=[], data=None) >>> print(s) (x+y) >>> s({}) >>> s({"x": [1]}) >>> s({"x": [1], "y": [2]}) [1, 2] >>>
Example
>>> from galactic.characteristics import Key, Sum >>> s = Sum(Key(name="x"), Key(name="y"), start=0, data="nan", transform=float) >>> print(s) (x+y) >>> s({}) nan >>> s({"x": 1}) nan >>> s({"x": 1, "y": 2}) 3.0 >>>
-
__init__
(*args, start=0, **kwargs)¶ Initialise a
Sum
instance.- Parameters
*args (
tuple
) – A collection ofCharacteristic
instances to sum (inherited fromComposite.__init__()
)**kwargs – Unused but useful for multi-class inheritance.
- Keyword Arguments
start – Initial data for the sum
transform (
Callable
) – A transform operation (inherited fromTransformation.__init__()
).data – Any python object (inherited from
Valued.__init__()
).
-
__call__
(individual=None)¶ Make this characteristic callable.
- Parameters
individual – Any python object
- Returns
the sum of all
Characteristic
instance calls on theindividual
or the default transformeddata
if aTypeError
or aValueError
is raised.- Return type
-
-
class
galactic.characteristics.
Comparison
(*args, strict=None, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
The
Comparison
class can be inherited to holdstrict
property. It is designed for subclassing.-
strict
¶ The strict property hold by this instance. It is a boolean flag used for strict (or not)
Comparison
.- Type
-
__init__
(*args, strict=None, **kwargs)¶ Initialise a
Comparison
instance.- Parameters
*args – Unused but useful for multi-class inheritance.
**kwargs – Unused but useful for multi-class inheritance.
- Keyword Arguments
strict – Is the comparison strict?
-
-
class
galactic.characteristics.
Set
(*args, values=None, **kwargs)¶ Bases:
galactic.characteristics.Characteristic
A
Set
characteristics can be inherited to hold a set of values property. It is designed for subclassing.-
values
¶ The values hold by this instance. It is used to hold a collection of values.
- Type
OrderedSet
-
__init__
(*args, values=None, **kwargs)¶ Initialise a
Set
instance.- Parameters
*args – Unused but useful for multi-class inheritance.
**kwargs – Unused but useful for multi-class inheritance.
- Keyword Arguments
values (
Collection
) – A collection of values to be compared with
-
-
galactic.characteristics.
register_classes
()¶ Register all classes defined in this module.