hdmf.common.resources module

class hdmf.common.resources.KeyTable(name='keys', data=[])

Bases: hdmf.container.Table

A table for storing keys used to reference external resources

Parameters:
add_row(key)
Parameters:key (str) – The user key that maps to the resource term / registry symbol.
class hdmf.common.resources.Key(key, table=None, idx=None)

Bases: hdmf.container.Row

A Row class for representing rows in the KeyTable

Parameters:
  • key (str) – The user key that maps to the resource term / registry symbol.
  • table (Table) – None
  • idx (int) – None
todict()
class hdmf.common.resources.ResourceTable(name='resources', data=[])

Bases: hdmf.container.Table

A table for storing names of ontology sources and their uri

Parameters:
add_row(resource, resource_uri)
Parameters:
  • resource (str) – The resource/registry that the term/symbol comes from.
  • resource_uri (str) – The URI for the resource term / registry symbol.
class hdmf.common.resources.Resource(resource, resource_uri, table=None, idx=None)

Bases: hdmf.container.Row

A Row class for representing rows in the ResourceTable

Parameters:
  • resource (str) – The resource/registry that the term/symbol comes from.
  • resource_uri (str) – The URI for the resource term / registry symbol.
  • table (Table) – None
  • idx (int) – None
todict()
class hdmf.common.resources.EntityTable(name='entities', data=[])

Bases: hdmf.container.Table

A table for storing the external resources a key refers to

Parameters:
add_row(keys_idx, resources_idx, entity_id, entity_uri)
Parameters:
  • keys_idx (int or Key) – The index into the keys table for the user key that maps to the resource term / registry symbol.
  • resources_idx (int or Resource) – The index into the ResourceTable.
  • entity_id (str) – The unique ID for the resource term / registry symbol.
  • entity_uri (str) – The URI for the resource term / registry symbol.
class hdmf.common.resources.Entity(keys_idx, resources_idx, entity_id, entity_uri, table=None, idx=None)

Bases: hdmf.container.Row

A Row class for representing rows in the EntityTable

Parameters:
  • keys_idx (int or Key) – The index into the keys table for the user key that maps to the resource term / registry symbol.
  • resources_idx (int or Resource) – The index into the ResourceTable.
  • entity_id (str) – The unique ID for the resource term / registry symbol.
  • entity_uri (str) – The URI for the resource term / registry symbol.
  • table (Table) – None
  • idx (int) – None
todict()
class hdmf.common.resources.ObjectTable(name='objects', data=[])

Bases: hdmf.container.Table

A table for storing objects (i.e. Containers) that contain keys that refer to external resources

Parameters:
add_row(object_id, field)
Parameters:
  • object_id (str) – The object ID for the Container/Data
  • field (str) – The field on the Container/Data that uses an external resource reference key
class hdmf.common.resources.Object(object_id, field, table=None, idx=None)

Bases: hdmf.container.Row

A Row class for representing rows in the ObjectTable

Parameters:
  • object_id (str) – The object ID for the Container/Data
  • field (str) – The field on the Container/Data that uses an external resource reference key
  • table (Table) – None
  • idx (int) – None
todict()
class hdmf.common.resources.ObjectKeyTable(name='object_keys', data=[])

Bases: hdmf.container.Table

A table for identifying which keys are used by which objects for referring to external resources

Parameters:
add_row(objects_idx, keys_idx)
Parameters:
  • objects_idx (int or Object) – the index into the objects table for the object that uses the key
  • keys_idx (int or Key) – the index into the key table that is used to make an external resource reference
class hdmf.common.resources.ObjectKey(objects_idx, keys_idx, table=None, idx=None)

Bases: hdmf.container.Row

A Row class for representing rows in the ObjectKeyTable

Parameters:
  • objects_idx (int or Object) – the index into the objects table for the object that uses the key
  • keys_idx (int or Key) – the index into the key table that is used to make an external resource reference
  • table (Table) – None
  • idx (int) – None
todict()
class hdmf.common.resources.ExternalResources(name, keys=None, resources=None, entities=None, objects=None, object_keys=None)

Bases: hdmf.container.Container

A table for mapping user terms (i.e. keys) to resource entities.

Parameters:
  • name (str) – the name of this ExternalResources container
  • keys (KeyTable) – the table storing user keys for referencing resources
  • resources (ResourceTable) – the table for storing names of resources and their uri
  • entities (EntityTable) – the table storing entity information
  • objects (ObjectTable) – the table storing object information
  • object_keys (ObjectKeyTable) – the table storing object-resource relationships
keys

the table storing user keys for referencing resources

resources

the table for storing names of resources and their uri

entities

the table storing entity information

objects

the table storing object information

object_keys

the table storing object-resource relationships

add_key(key_name)

Add a key to be used for making references to external resources

It is possible to use the same key_name to refer to different resources so long as the key_name is not used within the same object and field. To do so, this method must be called for the two different resources. The returned Key objects must be managed by the caller so as to be appropriately passed to subsequent calls to methods for storing information about the different resources.
Parameters:key_name (str) – the name of the key to be added
add_entity(key, resources_idx, entity_id, entity_uri)

Add an entity that will be referenced to using the given key

Parameters:
  • key (str or Key) – the key to associate the entity with
  • resources_idx (int or Resource) – the id of the resource
  • entity_id (str) – unique entity id
  • entity_uri (str) – the URI for the entity
add_resource(resource, uri)

Add resource name and uri to ResourceTable that will be referenced by the ResourceTable idx.

Parameters:
  • resource (str) – the name of the ontology resource
  • uri (str) – uri associated with ontology resource
add_object(container, field)

Add an object that references an external resource

Parameters:
  • container (str or AbstractContainer) – the Container/Data object to add or the object_id for the Container/Data object to add
  • field (str) – the field on the Container to add
add_external_reference(obj, key)
Specify that an object (i.e. container and field) uses a key to reference
an external resource
Parameters:
  • obj (int or Object) – the Object to that uses the Key
  • key (int or Key) – the Key that the Object uses
get_key(key_name, container=None, field=None)

Return a Key or a list of Key objects that correspond to the given key.

If container and field are provided, the Key that corresponds to the given name of the key for the given container and field is returned.
Parameters:
  • key_name (str) – the name of the key to get
  • container (str or AbstractContainer) – the Container/Data object that uses the key or the object_id for the Container/Data object that uses the key
  • field (str) – the field of the Container that uses the key
add_ref(container=None, field=None, key=None, resources_idx=None, resource_name=None, resource_uri=None, entity_id=None, entity_uri=None)

Add information about an external reference used in this file.

It is possible to use the same name of the key to refer to different resources so long as the name of the key is not used within the same object and field. This method does not support such functionality by default. The different keys must be added separately using add_key and passed to the key argument in separate calls of this method.
Parameters:
  • container (str or AbstractContainer) – the Container/Data object that uses the key or the object_id for the Container/Data object that uses the key
  • field (str) – the field of the Container/Data that uses the key
  • key (str or Key) – the name of the key or the Row object from the KeyTable for the key to add a resource for
  • resources_idx (Resource) – the resourcetable id
  • resource_name (str) – the name of the resource to be created
  • resource_uri (str) – the uri of the resource to be created
  • entity_id (str) – the identifier for the entity at the resource
  • entity_uri (str) – the URI for the identifier at the resource
add_keys(res_df)
Add key to be used for making references to external resources. This must be a DataFrame with the
following columns:
  • key_name: the key that will be used for referencing an external resource
  • resources_idx: the index for the resourcetable
  • entity_id: the index for the entity at the external resource
  • entity_uri: the URI for the entity at the external resource

It is possible to use the same name of the key to refer to different resources so long as the name of the key is not used within the same object and field. This method does not support such functionality. See add_key and add_resource.

Parameters:res_df (DataFrame) – the DataFrame with all the keys and their resources
Returns:a dict with the Key objects that were added
Return type:dict
get_keys(keys=None)
Return a DataFrame with information about keys used to make references to external resources.
The DataFrame will contain the following columns:
  • key_name: the key that will be used for referencing an external resource
  • resources_idx: the index for the resourcetable
  • entity_id: the index for the entity at the external resource
  • entity_uri: the URI for the entity at the external resource

It is possible to use the same key_name to refer to different resources so long as the key_name is not used within the same object and field. This method does not support such functionality by default. To select specific keys, use the keys argument to pass in the Key object(s) representing the desired keys. Note, if the same key_name is used more than once, multiple calls to this method with different Key objects will be required to keep the different instances separate. If a single call is made, it is left up to the caller to distinguish the different instances.

Parameters:keys (list or Key) – the Key(s) to get external resource data for
Returns:a DataFrame with keys and external resource data
Return type:DataFrame
data_type = 'ExternalResources'
namespace = 'hdmf-experimental'