hermes.model.merge.container
============================

.. py:module:: hermes.model.merge.container


Classes
-------

.. autoapisummary::

   hermes.model.merge.container._ld_merge_container
   hermes.model.merge.container.ld_merge_list
   hermes.model.merge.container.ld_merge_dict


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

.. py:class:: _ld_merge_container

   Abstract base class for ld_merge_dict and ld_merge_list,
   providing the merge containers with an override of :meth:`ld_container._to_native_python`.
   See also :class:`ld_dict`, :class:`ld_list` and :class:`ld_container`.


   .. py:method:: _to_native_python(full_iri: str, ld_value: Union[hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE, dict[str, hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE], list[str], str]) -> Union[ld_merge_dict, ld_merge_list, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE]

      Returns a native python version of ``ld_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
                       was embeded in ``self._data``.
      :type ld_value: EXPANDED_JSON_LD_VALUE | dict[str, EXPANDED_JSON_LD_VALUE] | list[str] | str

      :returns: The native python value of ``ld_value``.
      :rtype: ld_merge_dict | ld_merge_list | BASIC_TYPE | TIME_TYPE



.. py:class:: ld_merge_list(data: Union[list[str], list[dict[str, hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE]]], prov_doc: hermes.model.provenance.ld_prov.ld_prov_list = None, prov_objects: list[hermes.model.types.ld_dict] = 3 * [None], *, parent: Optional[hermes.model.types.ld_container] = None, key: Optional[str] = None, index: Optional[int] = None, context: Optional[list[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT]]] = None, strategies: dict[Optional[str], dict[Optional[str], hermes.model.merge.action.MergeAction]] = {})

   Bases: :py:obj:`_ld_merge_container`, :py:obj:`hermes.model.types.ld_list`


   ld_list wrapper to ensure the 'merge_container'-property does not get lost, while merging.
   See also :class:`ld_list` and :class:`ld_merge_container`.

   .. attribute:: strategies

      The strategies used inside the child
      ld_merge_dicts.

      :type: dict[str | None, dict[str | None, MergeAction]]


.. py:class:: ld_merge_dict(data: list[dict[str, hermes.model.types.ld_container.EXPANDED_JSON_LD_VALUE]], prov_doc: hermes.model.provenance.ld_prov.ld_prov_list = None, prov_objects: list[hermes.model.types.ld_dict] = 3 * [None], *, parent: Optional[Union[hermes.model.types.ld_dict, hermes.model.types.ld_list]] = None, key: Optional[str] = None, index: Optional[int] = None, context: Optional[list[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT]]] = None, strategies: dict[Optional[str], dict[Optional[str], hermes.model.merge.action.MergeAction]] = {})

   Bases: :py:obj:`_ld_merge_container`, :py:obj:`hermes.model.types.ld_dict`


   ld_dict wrapper providing methods to merge an object of this class with an ld_dict object.
   See also :class:`ld_dict` and :class:`ld_merge_container`.

   .. attribute:: strategies

      The strategies for merging different types of values in the ld_dicts.

      :type: dict[str | None, dict[str | None, MergeAction]]


   .. py:method:: update_context(other_context: Union[list[Union[str, hermes.model.types.ld_container.JSON_LD_CONTEXT_DICT]], None]) -> None

      Updates ``self`` s context with ``other_context``.
      JSON-LD processing prioritizes the context values in order (first least important, last most important).

      :param other_context: The context object that is added to ``self`` s context.
      :type other_context: list[str | JSON_LD_CONTEXT_DICT] | None

      :rtype: None



   .. py:method:: update(other: hermes.model.types.ld_dict) -> None

      Updates/ Merges ``self`` with the given ld_dict ``other``.
      Note that this overwrites :meth:`ld_dict.update`, and may cause unexpected behavior if not used carefully.

      :param other: The ld_container that is merged into ``self``.
      :type other: ld_dict

      :rtype: None



   .. py:method:: add_strategy(strategy: dict[Optional[str], dict[Optional[str], hermes.model.merge.action.MergeAction]]) -> None

      Adds ``strategy`` to the ``self.strategies``.

      :param strategy: The object describing how which object types are
                       supposed to be merged.
      :type strategy: dict[str | None, dict[str | None, MergeAction]]

      :rtype: None



   .. py:method:: __setitem__(key: str, value: Union[hermes.model.types.ld_container.JSON_LD_VALUE, hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list]) -> None

      Creates the new entry for ``self[key]`` using ``self.strategies`` on the values in ``self[key]`` and ``value``.
      Note that this overwrites :meth:`ld_dict.__setitem__` and may cause unexpected behavior if not used carefully.

      :param key: The key at which the value is updated/ merged at in ``self``.
      :type key: str
      :param value: The value that is merged into
                    ``self[key]``.
      :type value: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list



   .. py:method:: match(key: str, value: Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list], match: Callable[[Any, Any], bool]) -> Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_merge_dict, ld_merge_list]

      Returns the first item in ``self[key]`` for which ``match(item, value)`` returns ``True``.
      If no such item is found ``None`` is returned instead.

      :param key: The key to the items in ``self`` from which a match for ``value`` is searched.
      :type key: str
      :param value: The value a match is searched for in
                    ``self[key]``.
      :type value: Union[JSON_LD_VALUE, BASIC_TYPE, TIME_TYPE, ld_dict, ld_list]
      :param match: The method defining if two objects are a match.
      :type match: Callable[[Any, Any], bool]

      :returns:     The item in ``self[key]`` that is a match for``value`` if one exists otherwise ``None``.
      :rtype: BASIC_TYPE | TIME_TYPE | ld_merge_dict | ld_merge_list



   .. py:method:: _merge_item(key: str, value: Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list]) -> Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, ld_merge_dict, ld_merge_list]

      Applies the most suitable merge strategy to merge ``self[key]`` and value and then returns the result.

      :param key: The key to the entry in ``self`` that is to be merged with ``value``.
      :type key: str
      :param value: The value that is to be merged with ``self[key]``.
      :type value: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns:     The result of the merge from ``self[key]`` with ``value``.
      :rtype: BASIC_TYPE | TIME_TYPE | ld_merge_dict | ld_merge_list

      :raises MergeError: If there is no strategy for this key.



   .. py:method:: _add_related(rel: str, key: str, value: Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list]) -> None

      Adds an entry for ``rel`` to ``self`` containing which key and value is affected.

      :param rel: The "type" of the special entry (used as the key).
      :type rel: str
      :param key: The key of the affected key, value pair in ``self``.
      :type key: str
      :param value: The value of the affected key, value pair in ``self``.
      :type value: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None



   .. py:method:: reject(key: str, value: Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list]) -> None

      Adds an entry to ``self`` containing containing information that the key, value pair
      ``key``, ``value`` has been rejected in the merge.
      For further information see :meth:`ld_merge_dict._add_related`.

      :param key: The key of the rejected key, value pair in ``self``.
      :type key: str
      :param value: The value of the rejected key, value pair in ``self``.
      :type value: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None



   .. py:method:: replace(key: str, value: Union[hermes.model.types.ld_container.BASIC_TYPE, hermes.model.types.ld_container.TIME_TYPE, hermes.model.types.ld_dict, hermes.model.types.ld_list]) -> None

      Adds an entry to ``self`` containing containing information that the key, value pair
      ``key``, ``value`` was replaced in the merge.
      For further information see :meth:`ld_merge_dict._add_related`.

      :param key: The key of the old key, value pair in ``self``.
      :type key: str
      :param value: The value of the old key, value pair in ``self``.
      :type value: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :rtype: None



