ragraph.generic
¶
Generic purpose classes and methods such as metadata models.
Metadata includes the kinds, labels, weights and annotations that we assign to our data objects. Standardizing this enables a more predictable experience.
Annotations
¶
Bases: Mapping
Miscellaneous properties mapping such as tool-specific metadata.
Source code in ragraph/generic.py
Bound
¶
Numerical lower or upper bound for a value. Use with comparison operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Union[int, float]
|
Numerical bound value. |
required |
inclusive |
bool
|
Whether the bound is inclusive. |
True
|
report |
Optional[str]
|
Whether to report an "error", "warn" or nothing ( |
None
|
Source code in ragraph/generic.py
ContinuousDomain
¶
Numerical domain for a value. Use with "in" operator.
Source code in ragraph/generic.py
Convention
¶
Bases: StrEnum
Convention for matrix conversion to follow. Either:
- Inputs in rows, feedback above diagonal (IR_FAD)
- Inputs in columns, feedback below diagonal (IC_FBD)
Mapping
¶
A dictionary like object that with property-based access fields.
It's possible to include allowed keys, default values, and optional validators for certain keys/properties of a derived class.
Source code in ragraph/generic.py
as_dict
¶
Return a copy as a dictionary with all sub-mappings as dictionaries, too.
Source code in ragraph/generic.py
get
¶
items
¶
keys
¶
update
¶
Update multiple keys at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Dict[str, Any]
|
Dictionaries of key value pairs to update the set data with. |
()
|
kwargs |
Any
|
Keyword arguments to update the set data with. |
{}
|
Source code in ragraph/generic.py
validate
¶
Check whether the current data passes validation.
Source code in ragraph/generic.py
Metadata
¶
|
Metadata for graph elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str]
|
Instance name. Set to a copy of the UUID if |
None
|
kind |
Optional[str]
|
Kind or main category of this instance. |
None
|
labels |
Optional[List[str]]
|
Labels categorizing this instance. |
None
|
weights |
Optional[Dict[str, Union[int, float]]]
|
Dictionary of weights attached to this instance. |
None
|
annotations |
Optional[Union[Annotations, Dict[str, Any]]]
|
Miscellaneous properties of this instance. |
None
|
uuid |
Optional[Union[str, UUID]]
|
UUID of this instance, generated when |
None
|
Source code in ragraph/generic.py
annotations
property
writable
¶
|
Annotations of this instance.
Defaults to an empty Annotations
instance.
MetadataFilter
¶
|
Metadata filtering options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuids |
Optional[Union[Iterable[str], Iterable[UUID]]]
|
Filter by UUIDs. |
None
|
names |
Optional[Iterable[str]]
|
Filter by names. |
None
|
kinds |
Optional[Iterable[str]]
|
Filter by kinds. |
None
|
labels |
Optional[Iterable[str]]
|
Filter by labels. Items should match at least one. |
None
|
weights |
Optional[Iterable[str]]
|
Filter by weight labels. Items should match at least one. |
None
|
weight_domains |
Optional[Dict[str, ContinuousDomain]]
|
Filter items by weight domains. (upper/lower bound) |
None
|
annotations |
Optional[Iterable[str]]
|
Filter by annotation keys. Items should match at least one. |
None
|
Source code in ragraph/generic.py
check_annotations
¶
check_kinds
¶
check_labels
¶
check_names
¶
check_uuids
¶
check_weight_domains
¶
Check if item satisfies weight domains filter.
check_weights
¶
filter
¶
Filter data using the set metadata filters.
Source code in ragraph/generic.py
get_checks
¶
MetadataOptions
¶
|
Seen values in an iterable of Metadata instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objects |
Iterable[Metadata]
|
Objects derivated of the Metadata class. |
required |
skip_names |
bool
|
Whether to skip the names field. |
False
|
Source code in ragraph/generic.py
as_dict
¶
Serializable dictionary representation.
Source code in ragraph/generic.py
field
¶
A Mapping
field
is a property that utilizes the
Mapping
's data.
Use it like the @property
decorator and leave the function body blank (or pass):
By inspecting the wrapped method's name we derive the property's key.
Getting data from the mapping is done by retrieving the key from the set values. If that key is not found, an attempt is made on the defaults. An error is thrown when the key is neither to be found in the data or defaults.
Setting data checks for nested Mapping
keys to update those and
otherwise defaults to simply storing the value. Updating a nested
Mapping
field only updates the keys that are provided.
Deleting data pops the key from the set values, but does not remove any defaults.
Note
The method contents of a Mapping
field
are ignored.