ResultSet#

The ImmutableResultSet class can be used to wrap a list of Entry or EntryGroup instances a deliver a unified interface to load metadata from nested and / or grouped results.

Example

>>> session = api.connect_database()
>>> entry = api.find_entry(session, id=42)
>>> res = ImmutableResultSet(entry)

This will load all sibling Entries into the result set. I.e., if the composite entry has three members, the Composite EntryGroup and two child Entries, the ImmutableResultSet will have three UUIDs

>>> res.get('uuid')

>> [‘c1087040-5566-44b9-9852-ea600f73ae0c’, >> ‘0350c985-4e43-4876-a03a-7b6fb2a3a4b6’, >> ‘c6d6301b-8e1c-478f-9407-ce9a0c38dbb8’]

At the same time, if all members share a property, like their title the ImmutableResultSet will merge matching content:

>>> res.get('title')

>> ‘Awesome Composite Dataset’

Note that the return type is string, like the original title, not a list.

Alternatively, the API can return ImmutableResultSets if the API has a as_result arugment. The example above can be reproduced like:

>>> res = api.find_entry(session, id=42, as_result=True)

Reference#

class metacatalog.util.results.ImmutableResultSet(instance: Union[Entry, EntryGroup, ImmutableResultSet])#
property checksum: str#

Return the md5 checksum for this result set to easily tell it appart from others. The checksum is the md5 hash of all contained member checksums.

Changed in version 0.3.8: now hashing md5 of members instead of uuids

property checksums: List[str]#

New in version 0.3.8.

Return all checksums of all members

contains_uuid(uuid: str) bool#

Check if the given Entry or EntryGroup is present in this result set

property empty: bool#

New in version 0.4.1.

Returns True if there is no Entry associated to this result.

classmethod entry_set(entries: List[Entry])#

Return a set of entries to remove duplicates

Changed in version 0.3.8: Can now handle nested ResultSets

classmethod expand_entry(entry: Entry)#

Expand this Entry to all siblings.

Changed in version 0.3.8: Split datasets are now nested

Changed in version 0.6.11: the calling entry is now always part of the expansion set.

get(name: str, default=None)#

Get the given property from the result set. This function will iterate all member and nested Entries and return the values for the given property from all childs. It will return the set of all properties to remove duplicated metadata (i.e. for composites and split- datasets). If the set has a length of 1, the value itself will be returned

Changed in version 0.3.8: get can now handle nested ImmutableResultSets

Parameters:

name (str) – The name (key) of the requested parameter

Returns:

result – The value for the requested property. If more than one value is present, the of all values will be returned.

Return type:

set, any

get_data(verbose=False, merge=False, **kwargs) dict#

Return the data as a checksum indexed dict

classmethod load_base_group(entry: Entry)#

Returns the base EntryGroup of the given Entry. The base EntryGroup is the strongest grouping that requires expanding of the result set, to load all siblings. If there are no matching groups, None will be returned

Currently the order of importance is:

  • 'Composite'

  • 'Split dataset'

to_dict(orient: str = 'dict') dict#

Generate a full dictionary output of this result set.

Changed in version 0.6.8: Parameter orient added. The default value is ‘dict’, which returns a dictionary with unique keys. The value ‘uuids’ gives the dictionary with uuids as keys, this should make it easier to i.e. loop over the uuids / entities of an ImmutableResultSet.

to_short_info() dict#

Get a short unified version of the results.

property uuid: str#

Returns the first uuid in the ImmutableResultSet. This is the uuid of the base group, if it exists or the uuid of the first member. As uuids of members are sorted in uuids(self), self.uuids[0] always returns the same uuid for the same ImmutableResultSet.

property uuids: List[str]#

Return all uuids that form this result set

Changed in version 0.6.8: If a member in in _members is an ImmutableResultSet, call this method recursively

Changed in version 0.7.5: Members of ImmutableResultSets cannot be ImmutableResultSets again, reverted recursive method call from version 0.6.8