hermes.model.merge.action

Exceptions

MergeError

Class for any error while merging.

Classes

MergeAction

Base class for the different actions occuring druing a merge.

Reject

MergeAction providing a merge function for rejecting the incoming item.

Replace

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

Concat

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

Collect

MergeAction providing a merge function for appending the incoming items to the current items. But an item

MergeSet

MergeAction providing a merge function for merging the incoming items with the current items. An item

IdMerge

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

Module Contents

exception hermes.model.merge.action.MergeError

Bases: ValueError

Class for any error while merging.

class hermes.model.merge.action.MergeAction

Base class for the different actions occuring druing a merge.

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

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value.

Returns:

The merged value in an arbitrary format that is supported by ld_dict.__setitem__().

Return type:

JSON_LD_VALUE | BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

__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.)

class hermes.model.merge.action.Reject

Bases: MergeAction

MergeAction providing a merge function for rejecting the incoming item.

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update. This value won’t be changed.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value. This value will be rejected.

Returns:

The merged value. This value will always be value.

Return type:

ld_merge_list | str

class hermes.model.merge.action.Replace

Bases: MergeAction

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

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update. This value will bew replaced.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value. This value will be used instead of value.

Returns:

The merged value. This value will be update.

Return type:

BASIC_TYPE | TIME_TYPE | ld_dict | ld_list

class hermes.model.merge.action.Concat

Bases: MergeAction

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

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value.

Returns:

The merged value (value concatenated with update).

Return type:

ld_merge_list | str

class hermes.model.merge.action.Collect(match: Callable[[Any, Any], bool], reject_incoming: bool = True)

Bases: MergeAction

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

match

The function used to evaluate equality while merging.

Type:

Callable[[Any, Any], bool]

reject_incoming

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

Type:

bool

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value.

Returns:

The merged value.

Return type:

ld_merge_list | str

__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.)

class hermes.model.merge.action.MergeSet(match: Callable[[Any, Any], bool])

Bases: MergeAction

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.

match

The function used to evaluate equality while merging.

Type:

Callable[[Any, Any], bool]

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value.

Returns:

The merged value.

Return type:

ld_merge_list | str

__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.)

class hermes.model.merge.action.IdMerge

Bases: MergeAction

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

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

Parameters:
  • target (ld_merge_dict) – The ld_merge_dict inside of which the items are merged.

  • key (list[str | int]) – 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.

  • value (ld_merge_list | str) – The value inside target that is to be merged with update.

  • update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into target with value.

Returns:

The merged value.

Return type:

ld_merge_list | str