hermes.model.merge.action
Exceptions
Class for any error while merging. |
Classes
Base class for the different actions occuring druing a merge. |
|
|
|
|
|
|
|
|
|
|
|
|
Module Contents
- 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]]isvalueand for the outermost parent oftargetout_parentout_parent[key[0]]...[key[-1]]results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue.
- Returns:
The merged value in an arbitrary format that is supported by
ld_dict.__setitem__().- Return type:
- class hermes.model.merge.action.Reject
Bases:
MergeActionMergeActionproviding 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
updateand letstargetadd 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]]isvalueand for the outermost parent oftargetout_parentout_parent[key[0]]...[key[-1]]results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate. This value won’t be changed.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue. 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:
MergeActionMergeActionproviding 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
valuewith the new dataupdateand letstargetadd 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]]isvalueand for the outermost parent oftargetout_parentout_parent[key[0]]...[key[-1]]results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate. This value will bew replaced.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue. This value will be used instead ofvalue.
- Returns:
The merged value. This value will be
update.- Return type:
- class hermes.model.merge.action.Concat
Bases:
MergeActionMergeActionproviding 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
updateto the old datavalue.- 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]]isvalueand for the outermost parent oftargetout_parentout_parent[key[0]]...[key[-1]]results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue.
- Returns:
The merged value (
valueconcatenated withupdate).- Return type:
ld_merge_list | str
- class hermes.model.merge.action.Collect(match: Callable[[Any, Any], bool], reject_incoming: bool = True)
Bases:
MergeActionMergeActionproviding 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).- 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) fromvalueandupdate.- 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]]isvalueand for the outermost parent oftargetout_parentout_parent[key[0]]...[key[-1]]results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue.
- Returns:
The merged value.
- Return type:
ld_merge_list | str
- class hermes.model.merge.action.MergeSet(match: Callable[[Any, Any], bool])
Bases:
MergeActionMergeActionproviding 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.- 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) fromvalueandupdate.- 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]]isvalueand for the outermost parent oftargetout_parent out_parent[key[0]]…[key[-1]] results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue.
- Returns:
The merged value.
- Return type:
ld_merge_list | str
- class hermes.model.merge.action.IdMerge
Bases:
MergeActionMergeActionproviding 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]]isvalueand for the outermost parent oftargetout_parent out_parent[key[0]]…[key[-1]] results invalue.value (ld_merge_list | str) – The value inside
targetthat is to be merged withupdate.update (BASIC_TYPE | TIME_TYPE | ld_dict | ld_list) – The value that is to be merged into
targetwithvalue.
- Returns:
The merged value.
- Return type:
ld_merge_list | str