hermes.commands.process.standard_merge
======================================

.. py:module:: hermes.commands.process.standard_merge


Attributes
----------

.. autoapisummary::

   hermes.commands.process.standard_merge.DEFAULT_MATCH
   hermes.commands.process.standard_merge.MATCH_FUNCTION_FOR_TYPE
   hermes.commands.process.standard_merge.ACTIONS
   hermes.commands.process.standard_merge.PROV_STRATEGY
   hermes.commands.process.standard_merge.CODEMETA_STRATEGY


Classes
-------

.. autoapisummary::

   hermes.commands.process.standard_merge.CodemetaProcessPlugin


Functions
---------

.. autoapisummary::

   hermes.commands.process.standard_merge.match_equals
   hermes.commands.process.standard_merge.match_keys
   hermes.commands.process.standard_merge.match_person
   hermes.commands.process.standard_merge.match_multiple_types


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

.. py:function:: match_equals(left: Any, right: Any) -> bool

   Compares two objects with ==.

   :param left: The first object for the comparison.
   :type left: Any
   :param right: The second object for the comparison.
   :type right: Any

   :returns: The result of the comparison.
   :rtype: bool


.. py:function:: match_keys(*keys: list[str], fall_back_to_equals: bool = False) -> Callable[[Any, Any], bool]

   Creates a function taking to parameters that returns true
   if both given parameter have at least one common key in the given list of keys
   and for all common keys in the given list of keys the values of both objects are the same.

   If fall_back_to_equals is True, the returned function returns the value of normal == comparison
   if no key from keys is in both objects.

   :param keys: The list of important keys for the comparison method.
   :type keys: list[str]
   :param fall_back_to_equals: Whether or not a fall back option should be used.
   :type fall_back_to_equals: bool

   :returns: A function comparing two given objects values for the keys in keys.
   :rtype: Callable[[Any, Any], bool]


.. py:function:: match_person(left: Any, right: Any) -> bool

   Compares two objects assuming they are representing schema:Person's
   if they are not ld_dicts, == is used as a fallback.

   If both objects have an @id value, the truth value returned by this function is the comparison of both ids.

   If either other has no @id value and both objects have at least one email value,
   they are considered equal if they have one common email.

   If the equality of the objects is not yet decided, == comparison of the objects is returned.

   :param left: The first object for the comparison.
   :type left: Any
   :param right: The second object for the comparison.
   :type right: Any

   :returns: The result of the comparison.
   :rtype: bool


.. py:function:: match_multiple_types(*functions_for_types: list[tuple[str, Callable[[Any, Any], bool]]], fall_back_function: Callable[[Any, Any], bool] = match_keys('@id', fall_back_to_equals=True)) -> Callable[[Any, Any], bool]

   Returns a function that compares two objects using the given functions.

   :param functions_for_types: Tuples of type and match_function.
                               The returned function will compare two objects of a the same, given type with the specified function.
   :type functions_for_types: list[tuple[str, Callable[[Any, Any], bool]]]
   :param fall_back_function: The fallback for comparison if the objects that are being
                              compared don't have a common type with specified compare function or at least one object
                              is not a JSON-LD dictionary.
   :type fall_back_function: Callable[[Any, Any], bool]

   :returns: The function that compares the two given objects using the given functions.
   :rtype: Callable[[Any, Any], bool]


.. py:data:: DEFAULT_MATCH

   The default match function used for comparison.

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

.. py:data:: MATCH_FUNCTION_FOR_TYPE

   A dict containing for JSON_LD types the match function (not DEFAULT_MATCH).

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

.. py:data:: ACTIONS

   A dict containing some common MergeActions.

   :type: dict[str, MergeAction]

.. py:data:: PROV_STRATEGY

   MergeActions for provenance values.

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

.. py:data:: CODEMETA_STRATEGY

   MergeActions for the standard JSON_LD contexts objects.

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

.. py:class:: CodemetaProcessPlugin

   Bases: :py:obj:`hermes.commands.process.base.HermesProcessPlugin`


   Base plugin that defines additional merge strategies.


   .. py:method:: __call__(command: hermes.commands.base.HermesCommand) -> hermes.commands.process.base.ObjectStrategies

      Execute the hermes process plugin `self`.

      :param command: The command being executed.
      :type command: HermesProcessCommand

      :returns: The merge strategies.
      :rtype: dict[str | None, dict[str | None, MergeAction]]



   .. py:method:: get_schema_type_hierarchy()
      :classmethod:



   .. py:method:: get_schema_strategies(subtypes_for_types)
      :classmethod:



   .. py:method:: get_codemeta_strategies(subtypes_for_types)
      :classmethod:



