hermes.model.types.ld_container
===============================

.. py:module:: hermes.model.types.ld_container


Attributes
----------

.. autoapisummary::

   hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT
   hermes.model.types.ld_container.BASIC_TYPE
   hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE
   hermes.model.types.ld_container.COMPACTED_JSON_LD_VALUE
   hermes.model.types.ld_container.TIME_TYPE
   hermes.model.types.ld_container.JSON_LD_VALUE
   hermes.model.types.ld_container.NATIVE_LD_CONTAINER


Classes
-------

.. autoapisummary::

   hermes.model.types.ld_container.ld_container


Module Contents
---------------

.. py:type:: JSON_LD_CONTEXT_DICT
   :canonical: dict[str, Union[str, 'JSON_LD_CONTEXT_DICT']]


   Type description for a context object in JSON_LD

.. py:type:: BASIC_TYPE
   :canonical: Union[str, float, int, bool]


   All primitive types in Python recogniced by ld_containers

.. py:type:: EXPANDED_JSON_LD_VALUE
   :canonical: list[Union[dict[str, Union['EXPANDED_JSON_LD_VALUE', BASIC_TYPE]], 'EXPANDED_JSON_LD_VALUE', str]]


   Type description of an expanded JSON_LD object

.. py:type:: COMPACTED_JSON_LD_VALUE
   :canonical: Union[list[Union[dict[str, Union['COMPACTED_JSON_LD_VALUE', BASIC_TYPE]], BASIC_TYPE]], dict[str, Union['COMPACTED_JSON_LD_VALUE', BASIC_TYPE]]]


   Type description of an compacted JSON_LD object

.. py:type:: TIME_TYPE
   :canonical: Union[datetime, date, time]


   All time related types in Python recogniced by ld_Containers

.. py:type:: JSON_LD_VALUE
   :canonical: Union[list[Union['JSON_LD_VALUE', BASIC_TYPE, TIME_TYPE, 'ld_dict', 'ld_list']], dict[str, Union['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

.. py:type:: NATIVE_LD_CONTAINER
   :canonical: Union[list[Union['NATIVE_LD_CONTAINER', BASIC_TYPE, TIME_TYPE]], dict[str, Union['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).

.. py:class:: ld_container(data: EXPANDED_JSON_LD_VALUE, *, parent: Optional[Union[hermes.model.types.ld_dict.ld_dict, hermes.model.types.ld_list.ld_list]] = None, key: Optional[str] = None, index: Optional[int] = None, context: Optional[list[Union[str, JSON_LD_CONTEXT_DICT]]] = 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.

   .. attribute:: active_ctx

      The active context that is used by the json-ld processor.

   .. attribute:: 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]

   .. attribute:: index

      The index into the parent container if it is a list.

      :type: int

   .. attribute:: key

      The key into the inner most parent that is a dict of this ld_container.

      :type: str

   .. attribute:: parent

      The ld_container this one is directly contained in.

      :type: ld_container

   .. attribute:: ld_proc

      (class attribute) The JSON-LD processor object for all ld_container.

      :type: JsonLdProcessor


   .. py:method:: add_context(context: list[Union[str | JSON_LD_CONTEXT_DICT]]) -> None

      Add the given context to the ld_container.

      :param context: The context to be added to self.
      :type context: list[str | JSON_LD_CONTEXT_DICT]

      :rtype: None



   .. py:property:: full_context
      :type: list[Union[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]


   .. py:property:: path
      :type: list[Union[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]


   .. py:property:: ld_value
      :type: 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


   .. py:method:: _to_native_python(full_iri: str, ld_value: Union[EXPANDED_JSON_LD_VALUE, dict[str, EXPANDED_JSON_LD_VALUE], list[str], str]) -> Union[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.

      :param full_iri: The expanded iri of the key of ld_value / self (later if self is not a dictionary).
      :type full_iri: str
      :param ld_value: The value thats
                       native python value is requested.
                       ld_value has to be valid expanded JSON-LD if it were inside self._data.
      :type ld_value: EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str

      :returns: The native python value of the ld_value.
      :rtype: ld_dict | ld_list | BASIC_TYPE | TIME_TYPE



   .. py:method:: _to_expanded_json(value: JSON_LD_VALUE) -> Union[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.

      :param 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.
      :type value: JSON_LD_VALUE

      :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
      :rtype: EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE]



   .. py:method:: __repr__() -> str

      Returns a short string representation of this object.

      :returns: The short representation of self.
      :rtype: str



   .. py:method:: __str__() -> str

      Returns a string representation of this object.

      :returns: The representation of self.
      :rtype: (str)



   .. py:method:: compact(context: Optional[Union[list[Union[JSON_LD_CONTEXT_DICT, str]], JSON_LD_CONTEXT_DICT, str]] = None) -> COMPACTED_JSON_LD_VALUE

      Returns the compacted version of the given ld_container using its context only if none was supplied.

      :param context: The context to use for the compaction. If None the context of self is used.
      :type context: list[JSON_LD_CONTEXT_DICT | str] | JSON_LD_CONTEXT_DICT | str | None

      :returns: The compacted version of selfs JSON-LD representation.
      :rtype: COMPACTED_JSON_LD_VALUE



   .. py:method:: to_native_python()
      :abstractmethod:



   .. py:method:: merge_to_list(*args: tuple[Any]) -> list[Any]
      :classmethod:


      Returns a list that is contains all non-list items from args and all items in the lists in args.

      :param args: The items that should be put into one list.
      :type args: tuple[Any]

      :returns: A list containing all non-list items and all items from lists in args. (Same order as in args)
      :rtype: list[Any]



   .. py:method:: is_ld_node(ld_value: Any) -> bool
      :classmethod:


      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}].

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent an expanded JSON-LD node.
      :rtype: bool



   .. py:method:: is_ld_id(ld_value: Any) -> bool
      :classmethod:


      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": ...}].

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent an expanded JSON-LD node containing only an @id value.
      :rtype: bool



   .. py:method:: is_ld_value(ld_value: Any) -> bool
      :classmethod:


      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}].

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent an expanded JSON-LD value.
      :rtype: bool



   .. py:method:: is_typed_ld_value(ld_value: Any) -> bool
      :classmethod:


      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}].

      :param ld_value: The value that is checked.
      :type ld_value: Any

      Returns
          bool: Wheter or not ld_value could represent an expanded JSON-LD value containing a value type.



   .. py:method:: is_json_id(ld_value: Any) -> bool
      :classmethod:


      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": ...}.

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent a non-expanded JSON-LD node containing only an @id value.
      :rtype: bool



   .. py:method:: is_json_value(ld_value: Any) -> bool
      :classmethod:


      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}.

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent a non-expanded JSON-LD value.
      :rtype: bool



   .. py:method:: is_typed_json_value(ld_value: Any) -> bool
      :classmethod:


      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}.

      :param ld_value: The value that is checked.
      :type ld_value: Any

      :returns: Wheter or not ld_value could represent a non-expanded JSON-LD value containing a value type.
      :rtype: bool



   .. py:method:: typed_ld_to_py(data: list[dict[str, BASIC_TYPE]], **kwargs) -> Union[BASIC_TYPE, TIME_TYPE]
      :classmethod:


      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.

      :param data: The value that is that is converted into its native python version.
      :type data: list[dict[str, BASIC_TYPE]]

      :returns: The native python version of data.
      :rtype: BASIC_TYPE | TIME_TYPE



   .. py:method:: are_values_equal(first: dict[str, Union[BASIC_TYPE, TIME_TYPE]], second: dict[str, Union[BASIC_TYPE, TIME_TYPE]]) -> bool
      :classmethod:


      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.

      :param first: The first value of the comparison
      :type first: dict[str, Union[BASIC_TYPE, TIME_TYPE]]
      :param second: The second value of the comparison
      :type second: dict[str, Union[BASIC_TYPE, TIME_TYPE]]

      :returns: Whether the values are considered equal or not.
      :rtype: bool



