hermes.model.merge.action
=========================

.. py:module:: hermes.model.merge.action


Exceptions
----------

.. autoapisummary::

   hermes.model.merge.action.MergeError


Classes
-------

.. autoapisummary::

   hermes.model.merge.action.MergeAction
   hermes.model.merge.action.Reject
   hermes.model.merge.action.Replace
   hermes.model.merge.action.Concat
   hermes.model.merge.action.Collect
   hermes.model.merge.action.MergeSet
   hermes.model.merge.action.IdMerge


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

.. py:exception:: MergeError

   Bases: :py:obj:`ValueError`


   Class for any error while merging.


.. py:class:: MergeAction

   Base class for the different actions occuring druing a merge.


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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.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]
      :abstractmethod:


      An abstract method that needs to be implemented by all subclasses
      to have a generic way to use the merge actions.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent ``out_parent[key[0]]...[key[-1]]`` results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target``
                     with ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns:     The merged value in an arbitrary format that is supported by :meth:`ld_dict.__setitem__`.
      :rtype: JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list



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

      A generic stringify method for MergeActions.
      Please overwrite this method if your MergeAction should be represented differently in the provenance data.
      (I.e. if not all important attributes are recorded or some attributes string representation is not adequat.)



.. py:class:: Reject

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for rejecting the incoming item.


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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]) -> hermes.model.merge.container.ld_merge_list

      Rejects the new data ``update`` and lets ``target`` add an entry to itself
      documenting what data has been rejected.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent ``out_parent[key[0]]...[key[-1]]`` results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
                    This value won't be changed.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target`` with
                     ``value``. This value will be rejected.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value. This value will always be ``value``.
      :rtype: ld_merge_list | str



.. py:class:: Replace

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for replacing the current item with the incoming one.


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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, hermes.model.types.ld_dict, hermes.model.types.ld_list]

      Replaces the old data ``value`` with the new data ``update``
      and lets ``target`` add an entry to itself documenting what data has been replaced.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent ``out_parent[key[0]]...[key[-1]]`` results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
                    This value will bew replaced.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target`` with
                     ``value``. This value will be used instead of ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value. This value will be ``update``.
      :rtype: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list



.. py:class:: Concat

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for appending the incoming items to the current items.


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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]) -> hermes.model.merge.container.ld_merge_list

      Concatenates the new data ``update`` to the old data ``value``.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent ``out_parent[key[0]]...[key[-1]]`` results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target``
                     with ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value (``value`` concatenated with ``update``).
      :rtype: ld_merge_list | str



.. py:class:: Collect(match: Callable[[Any, Any], bool], reject_incoming: bool = True)

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for appending the incoming items to the current items. But an item
   will only be appended if it has no match in the list of current items (including the already appended ones).

   .. attribute:: match

      The function used to evaluate equality while merging.

      :type: Callable[[Any, Any], bool]

   .. attribute:: reject_incoming

      Whether the incoming item in a match should get rejected (True) or replaced (False).

      :type: bool


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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]) -> hermes.model.merge.container.ld_merge_list

      Collects the unique items (according to :attr:`match`) from ``value`` and ``update``.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent ``out_parent[key[0]]...[key[-1]]`` results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target``
                     with ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value.
      :rtype: ld_merge_list | str



   .. py:method:: __repr__()

      A generic stringify method for MergeActions.
      Please overwrite this method if your MergeAction should be represented differently in the provenance data.
      (I.e. if not all important attributes are recorded or some attributes string representation is not adequat.)



.. py:class:: MergeSet(match: Callable[[Any, Any], bool])

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for merging the incoming items with the current items. An item
   will be appended if it has no match in the list of current items (including the already appended ones), otherwise
   it will be merged with its first match.

   .. attribute:: match

      The function used to evaluate equality while merging.

      :type: Callable[[Any, Any], bool]


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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]) -> hermes.model.merge.container.ld_merge_list

      Merges similar items (according to :attr:`match`) from ``value`` and ``update``.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent out_parent[key[0]]...[key[-1]] results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target``
                     with ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value.
      :rtype: ld_merge_list | str



   .. py:method:: __repr__()

      A generic stringify method for MergeActions.
      Please overwrite this method if your MergeAction should be represented differently in the provenance data.
      (I.e. if not all important attributes are recorded or some attributes string representation is not adequat.)



.. py:class:: IdMerge

   Bases: :py:obj:`MergeAction`


   :class:`MergeAction` providing a merge function for merging ids, i.e. error if not equals else do nothing.


   .. py:method:: merge(target: hermes.model.merge.container.ld_merge_dict, key: list[Union[str, int]], value: Union[hermes.model.merge.container.ld_merge_list, str], update: 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]) -> hermes.model.merge.container.ld_merge_list

      Error if value != update or key != "@id". Else do nothing.

      :param target: The ld_merge_dict inside of which the items are merged.
      :type target: ld_merge_dict
      :param key: The "path" of keys so that ``target[key[-1]]`` is ``value`` and for the outermost
                  parent of ``target`` out_parent out_parent[key[0]]...[key[-1]] results in ``value``.
      :type key: list[str | int]
      :param value: The value inside ``target`` that is to be merged with ``update``.
      :type value: ld_merge_list | str
      :param update: The value that is to be merged into ``target``
                     with ``value``.
      :type update: BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

      :returns: The merged value.
      :rtype: ld_merge_list | str



