mex.common.merged package

Submodules

mex.common.merged.main module

mex.common.merged.main._apply_additive_rule(merged_dict: dict[str, Any], mergeable_fields: list[str], rule: AdditiveAccessPlatform | AdditiveActivity | AdditiveBibliographicResource | AdditiveConsent | AdditiveContactPoint | AdditiveDistribution | AdditiveOrganization | AdditiveOrganizationalUnit | AdditivePerson | AdditivePrimarySource | AdditiveResource | AdditiveVariable | AdditiveVariableGroup) None

Merge the values from an additive rule into a merged_dict.

Parameters:
  • merged_dict – Mapping from field names to lists of merged values

  • mergeable_fields – List of mergeable field names

  • rule – Additive rule with values to be added

mex.common.merged.main._apply_subtractive_rule(merged_dict: dict[str, Any], mergeable_fields: list[str], rule: SubtractiveAccessPlatform | SubtractiveActivity | SubtractiveBibliographicResource | SubtractiveConsent | SubtractiveContactPoint | SubtractiveDistribution | SubtractiveOrganization | SubtractiveOrganizationalUnit | SubtractivePerson | SubtractivePrimarySource | SubtractiveResource | SubtractiveVariable | SubtractiveVariableGroup) None

Prune values of a subtractive rule from a merged_dict.

Parameters:
  • merged_dict – Mapping from field names to lists of merged values

  • mergeable_fields – List of mergeable field names

  • rule – Subtractive rule with values to remove

mex.common.merged.main._merge_extracted_items_and_apply_preventive_rule(merged_dict: dict[str, Any], mergeable_fields: list[str], extracted_items: list[ExtractedAccessPlatform | ExtractedActivity | ExtractedBibliographicResource | ExtractedConsent | ExtractedContactPoint | ExtractedDistribution | ExtractedOrganization | ExtractedOrganizationalUnit | ExtractedPerson | ExtractedPrimarySource | ExtractedResource | ExtractedVariable | ExtractedVariableGroup], rule: PreventiveAccessPlatform | PreventiveActivity | PreventiveBibliographicResource | PreventiveConsent | PreventiveContactPoint | PreventiveDistribution | PreventiveOrganization | PreventiveOrganizationalUnit | PreventivePerson | PreventivePrimarySource | PreventiveResource | PreventiveVariable | PreventiveVariableGroup | None) None

Merge a list of extracted items while applying a preventive rule.

Collect unique values from the extracted items and write them into merged_dict, unless the primary source of the extracted item was blocked by the rule.

Parameters:
  • merged_dict – Mapping from field names to lists of merged values

  • mergeable_fields – List of mergeable field names

  • extracted_items – List of extracted items

  • rule – Preventive rules with primary source identifiers, can be None

mex.common.merged.main.create_merged_item(identifier: Identifier, extracted_items: list[ExtractedAccessPlatform | ExtractedActivity | ExtractedBibliographicResource | ExtractedConsent | ExtractedContactPoint | ExtractedDistribution | ExtractedOrganization | ExtractedOrganizationalUnit | ExtractedPerson | ExtractedPrimarySource | ExtractedResource | ExtractedVariable | ExtractedVariableGroup], rule_set: AccessPlatformRuleSetRequest | ActivityRuleSetRequest | BibliographicResourceRuleSetRequest | ConsentRuleSetRequest | ContactPointRuleSetRequest | DistributionRuleSetRequest | OrganizationRuleSetRequest | OrganizationalUnitRuleSetRequest | PersonRuleSetRequest | PrimarySourceRuleSetRequest | ResourceRuleSetRequest | VariableRuleSetRequest | VariableGroupRuleSetRequest | AccessPlatformRuleSetResponse | ActivityRuleSetResponse | BibliographicResourceRuleSetResponse | ConsentRuleSetResponse | ContactPointRuleSetResponse | DistributionRuleSetResponse | OrganizationRuleSetResponse | OrganizationalUnitRuleSetResponse | PersonRuleSetResponse | PrimarySourceRuleSetResponse | ResourceRuleSetResponse | VariableRuleSetResponse | VariableGroupRuleSetResponse | None, validate_cardinality: Literal[False]) PreviewAccessPlatform | PreviewActivity | PreviewBibliographicResource | PreviewConsent | PreviewContactPoint | PreviewDistribution | PreviewOrganization | PreviewOrganizationalUnit | PreviewPerson | PreviewPrimarySource | PreviewResource | PreviewVariable | PreviewVariableGroup
mex.common.merged.main.create_merged_item(identifier: Identifier, extracted_items: list[ExtractedAccessPlatform | ExtractedActivity | ExtractedBibliographicResource | ExtractedConsent | ExtractedContactPoint | ExtractedDistribution | ExtractedOrganization | ExtractedOrganizationalUnit | ExtractedPerson | ExtractedPrimarySource | ExtractedResource | ExtractedVariable | ExtractedVariableGroup], rule_set: AccessPlatformRuleSetRequest | ActivityRuleSetRequest | BibliographicResourceRuleSetRequest | ConsentRuleSetRequest | ContactPointRuleSetRequest | DistributionRuleSetRequest | OrganizationRuleSetRequest | OrganizationalUnitRuleSetRequest | PersonRuleSetRequest | PrimarySourceRuleSetRequest | ResourceRuleSetRequest | VariableRuleSetRequest | VariableGroupRuleSetRequest | AccessPlatformRuleSetResponse | ActivityRuleSetResponse | BibliographicResourceRuleSetResponse | ConsentRuleSetResponse | ContactPointRuleSetResponse | DistributionRuleSetResponse | OrganizationRuleSetResponse | OrganizationalUnitRuleSetResponse | PersonRuleSetResponse | PrimarySourceRuleSetResponse | ResourceRuleSetResponse | VariableRuleSetResponse | VariableGroupRuleSetResponse | None, validate_cardinality: Literal[True]) MergedAccessPlatform | MergedActivity | MergedBibliographicResource | MergedConsent | MergedContactPoint | MergedDistribution | MergedOrganization | MergedOrganizationalUnit | MergedPerson | MergedPrimarySource | MergedResource | MergedVariable | MergedVariableGroup

Merge a list of extracted items with a set of rules.

Parameters:
  • identifier – Identifier the finished merged item should have

  • extracted_items – List of extracted items, can be empty

  • rule_set – Rule set, with potentially empty rules

  • validate_cardinality – Merged items validate the existence of required fields and the lengths of lists, set this to False to avoid this and return a “preview” of a merged item instead of a valid merged item

Raises:

MergingError – When the given items cannot be merged

Returns:

Instance of a merged or preview item

mex.common.merged.utils module

mex.common.merged.utils.extend_list_in_dict(dict_: dict[str, list[T]], key: str, item: list[T] | T | None) None

Extend a list in a dict for a given key with the given unique item(s).

mex.common.merged.utils.prune_list_in_dict(dict_: dict[str, list[T]], key: str, item: list[T] | T | None) None

Safely remove item(s) from a list in a dict for the given key.

Module contents