hermes.model.types.ld_container
Attributes
Type description for a context object in JSON_LD |
|
All primitive types in Python recogniced by ld_containers |
|
Type description of an expanded JSON_LD object |
|
Type description of an compacted JSON_LD object |
|
All time related types in Python recogniced by ld_Containers |
|
Type description of valid JSON_LD objects that are partially represented by ld_containers |
|
Type description of the native python version of ld_containers (i.e. if the ld_container(s) is/ are replaced). |
Classes
Base class for Linked Data containers. |
Module Contents
- type hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT = dict[str, str | 'JSON_LD_CONTEXT_DICT']
Type description for a context object in JSON_LD
- type hermes.model.types.ld_container.BASIC_TYPE = str | float | int | bool
All primitive types in Python recogniced by ld_containers
- type hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE = list[dict[str, 'EXPANDED_JSON_LD_VALUE' | BASIC_TYPE] | 'EXPANDED_JSON_LD_VALUE' | str]
Type description of an expanded JSON_LD object
- type hermes.model.types.ld_container.COMPACTED_JSON_LD_VALUE = list[dict[str, 'COMPACTED_JSON_LD_VALUE' | BASIC_TYPE] | BASIC_TYPE] | dict[str, 'COMPACTED_JSON_LD_VALUE' | BASIC_TYPE]
Type description of an compacted JSON_LD object
- type hermes.model.types.ld_container.TIME_TYPE = datetime | date | time
All time related types in Python recogniced by ld_Containers
- type hermes.model.types.ld_container.JSON_LD_VALUE = list['JSON_LD_VALUE' | BASIC_TYPE | TIME_TYPE | 'ld_dict' | 'ld_list'] | dict[str, 'JSON_LD_VALUE' | BASIC_TYPE | TIME_TYPE | 'ld_dict' | 'ld_list']
Type description of valid JSON_LD objects that are partially represented by ld_containers
- type hermes.model.types.ld_container.NATIVE_LD_CONTAINER = list['NATIVE_LD_CONTAINER' | BASIC_TYPE | TIME_TYPE] | dict[str, 'NATIVE_LD_CONTAINER' | BASIC_TYPE | TIME_TYPE]
Type description of the native python version of ld_containers (i.e. if the ld_container(s) is/ are replaced).
- class hermes.model.types.ld_container.ld_container(data: EXPANDED_JSON_LD_VALUE, *, parent: hermes.model.types.ld_dict.ld_dict | hermes.model.types.ld_list.ld_list | None = None, key: str | None = None, index: int | None = None, context: list[str | JSON_LD_CONTEXT_DICT] | None = None)
Base class for Linked Data containers.
A linked data container impelements a view on the expanded form of an JSON-LD document. It allows to easily interacts them by hinding all the nesting and automatically mapping between different forms.
- context
The context exclusive to this ld_container and all its childs (it can still be the same as e.g. parent.context)
- Type:
list[str | JSON_LD_CONTEXT_DICT]
- add_context(context: list[str | JSON_LD_CONTEXT_DICT]) None
Add the given context to the ld_container.
- Parameters:
context (list[str | JSON_LD_CONTEXT_DICT]) – The context to be added to self.
- Return type:
None
- property full_context: list[str | JSON_LD_CONTEXT_DICT]
The context of the ld_container merged with the full_context of its parent via ld_container.merge_to_list or just the context of this ld_container if self.parent is None.
- Type:
list[str | JSON_LD_CONTEXT_DICT]
- property path: list[str | int]
The path from selfs outer most parent to it self. Let parent be the outer most parent of self. Start with index = 1 and iteratively set parent to parent[path[index]] and then increment index until index == len(path) to get parent is self == true.
- Type:
list[str | int]
- property ld_value: EXPANDED_JSON_LD_VALUE
The expanded JSON-LD value of this container. This value is the basis of all operations and a reference to the original is returned and not a copy. Do not modify unless strictly necessary and you know what you do. Otherwise unexpected behavior may occur.
- Type:
EXPANDED_JSON_LD_VALUE
- _to_native_python(full_iri: str, ld_value: EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str) ld_container | BASIC_TYPE | TIME_TYPE
Returns a native python version of the given value pretending the value is in self and full_iri its key.
- Parameters:
full_iri (str) – The expanded iri of the key of ld_value / self (later if self is not a dictionary).
ld_value (EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str) – The value thats native python value is requested. ld_value has to be valid expanded JSON-LD if it were inside self._data.
- Returns:
The native python value of the ld_value.
- Return type:
- _to_expanded_json(value: JSON_LD_VALUE) EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE]
Returns an expanded version of the given value.
The item_list/ data_dict of self will be substituted with value. Value can be an ld_container or contain zero or more. Then the _data of the inner most ld_dict that contains or is self will be expanded using the JSON_LD-Processor. If self and none of self’s parents is an ld_dict, use the key from outer most ld_list to generate a minimal dict.
The result of this function is what value has turned into.
- Parameters:
value (JSON_LD_VALUE) –
The value that is to be expanded. Different types are expected based on the type of self
If type(self) == ld_dict: value must be a dict
If type(self) == ld_list: value must be a list
value will be expanded as if it was the data_dict/ the item_list of self.
- Returns:
The expanded version of value i.e. the data_dict/ item_list of self if it had been value. The return type is based on the type of self:
If type(self) == ld_dict: the returned values type is dict
If type(self) == ld_list: the returned values type is list
- Return type:
EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE]
- __repr__() str
Returns a short string representation of this object.
- Returns:
The short representation of self.
- Return type:
str
- __str__() str
Returns a string representation of this object.
- Returns:
The representation of self.
- Return type:
(str)
- compact(context: list[JSON_LD_CONTEXT_DICT | str] | JSON_LD_CONTEXT_DICT | str | None = None) COMPACTED_JSON_LD_VALUE
Returns the compacted version of the given ld_container using its context only if none was supplied.
- Parameters:
context (list[JSON_LD_CONTEXT_DICT | str] | JSON_LD_CONTEXT_DICT | str | None) – The context to use for the compaction. If None the context of self is used.
- Returns:
The compacted version of selfs JSON-LD representation.
- Return type:
COMPACTED_JSON_LD_VALUE
- classmethod merge_to_list(*args: tuple[Any]) list[Any]
Returns a list that is contains all non-list items from args and all items in the lists in args.
- Parameters:
args (tuple[Any]) – The items that should be put into one list.
- Returns:
A list containing all non-list items and all items from lists in args. (Same order as in args)
- Return type:
list[Any]
- classmethod is_ld_node(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD node.
I.e. if ld_value is of the form [{a: b, …, y: z}].
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent an expanded JSON-LD node.
- Return type:
bool
- classmethod is_ld_id(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD node containing only an @id value.
I.e. if ld_value is of the form [{“@id”: …}].
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent an expanded JSON-LD node containing only an @id value.
- Return type:
bool
- classmethod is_ld_value(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD value.
I.e. if ld_value is of the form [{“@value”: a, …, x: z}].
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent an expanded JSON-LD value.
- Return type:
bool
- classmethod is_typed_ld_value(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing an expanded JSON-LD value containing a value type.
I.e. if ld_value is of the form [{“@value”: a, “@type”: b, …, x: z}].
- Parameters:
ld_value (Any) – The value that is checked.
- Returns
bool: Wheter or not ld_value could represent an expanded JSON-LD value containing a value type.
- classmethod is_json_id(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD node containing only an @id value.
I.e. if ld_value is of the form {“@id”: …}.
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent a non-expanded JSON-LD node containing only an @id value.
- Return type:
bool
- classmethod is_json_value(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD value.
I.e. if ld_value is of the form {“@value”: b, …, x: z}.
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent a non-expanded JSON-LD value.
- Return type:
bool
- classmethod is_typed_json_value(ld_value: Any) bool
Returns wheter the given value is considered to be possible of representing a non-expanded JSON-LD value containing a value type.
I.e. if ld_value is of the form {“@value”: a, “@type”: b, …, x: z}.
- Parameters:
ld_value (Any) – The value that is checked.
- Returns:
Wheter or not ld_value could represent a non-expanded JSON-LD value containing a value type.
- Return type:
bool
- classmethod typed_ld_to_py(data: list[dict[str, BASIC_TYPE]], **kwargs) BASIC_TYPE | TIME_TYPE
Returns the value of the given expanded JSON-LD value containing a value type converted into that type. Meaning the native python version of the JSON-LD value data is returned. ld_container.is_typed_ld_value(data) must return True.
- Parameters:
data (list[dict[str, BASIC_TYPE]]) – The value that is that is converted into its native python version.
- Returns:
The native python version of data.
- Return type:
BASIC_TYPE | TIME_TYPE
- classmethod are_values_equal(first: dict[str, BASIC_TYPE | TIME_TYPE], second: dict[str, BASIC_TYPE | TIME_TYPE]) bool
Returns whether or not the given expanded JSON-LD values are considered equal. The comparison compares the “@id” values first and returns the result if it is conclusive.
If the comparison is inconclusive i.e. exactly one or zero of both values have an “@id” value: Return whether or not all other keys exist in both values and all values of the keys are the same.
- Parameters:
first (dict[str, Union[BASIC_TYPE, TIME_TYPE]]) – The first value of the comparison
second (dict[str, Union[BASIC_TYPE, TIME_TYPE]]) – The second value of the comparison
- Returns:
Whether the values are considered equal or not.
- Return type:
bool