API Documentation

Providers module

This module implements a skosprovider.providers.VocabularyProvider for http://www.heritagedata.org.

class skosprovider_heritagedata.providers.HeritagedataProvider(metadata, **kwargs)[source]

A provider that can work with the Heritagedata services of http://www.heritagedata.org/blog/services/

expand(id)[source]
Expand a concept or collection to all it’s narrower concepts.
If the id passed belongs to a skosprovider.skos.Concept, the id of the concept itself should be include in the return value.
Parameters:id (str) – A concept or collection id.
Returns:A lst of id’s. Returns false if the input id does not exists
find(query, **kwargs)[source]

Find concepts that match a certain query.

Currently query is expected to be a dict, so that complex queries can be passed. You can use this dict to search for concepts or collections with a certain label, with a certain type and for concepts that belong to a certain collection.

Warning

The underlying service returns labels without specifying if they are prefLabels or altLabels. For a certain concept several labels are returned. This method does not return labels, but returns concepts. When multiple labels are detected for a single concept, only one label is attached to this concept. Since no information is present about the type of this label, this can be an altLabel for a concept where a prefLabel exists.

# Find anything that has a label of church.
provider.find({'label': 'church'}

# Find all concepts that are a part of collection 5.
provider.find({'type': 'concept', 'collection': {'id': 5})

# Find all concepts, collections or children of these
# that belong to collection 5.
provider.find({'collection': {'id': 5, 'depth': 'all'})
Parameters:query

A dict that can be used to express a query. The following keys are permitted:

  • label: Search for something with this label value. An empty label is equal to searching for all concepts.
  • type: Limit the search to certain SKOS elements. If not present all is assumed:
  • collection: Search only for concepts belonging to a certain collection. This argument should be a dict with two keys:
    • id: The id of a collection. Required.
    • depth: Can be members or all. Optional. If not present, members is assumed, meaning only concepts or collections that are a direct member of the collection should be considered. When set to all, this method should return concepts and collections that are a member of the collection or are a narrower concept of a member of the collection.
Returns:A lst of concepts and collections. Each of these is a dict with the following keys:
  • id: id within the conceptscheme
  • uri: uri of the concept or collection
  • type: concept or collection
  • label: A label to represent the concept or collection. It is determined by looking at the **kwargs parameter, the default language of the provider and finally falls back to en.
get_all(**kwargs)[source]

Not supported: This provider does not support this. The amount of results is too large

get_by_id(id)[source]

Get a skosprovider.skos.Concept or skosprovider.skos.Collection by id

Parameters:id ((str)) – integer id of the skosprovider.skos.Concept or skosprovider.skos.Concept
Returns:corresponding skosprovider.skos.Concept or skosprovider.skos.Concept. Returns False if non-existing id
get_by_uri(uri)[source]

Get a skosprovider.skos.Concept or skosprovider.skos.Collection by uri

Parameters:uri ((str)) – string uri of the skosprovider.skos.Concept or skosprovider.skos.Concept
Returns:corresponding skosprovider.skos.Concept or skosprovider.skos.Concept. Returns False if non-existing id
get_children_display(id, **kwargs)[source]

Return a list of concepts or collections that should be displayed under this concept or collection.

Parameters:id (str) – A concept or collection id.
Returns:A lst of concepts and collections.
get_top_concepts(**kwargs)[source]

Returns all concepts that form the top-level of a display hierarchy.

Returns:A lst of concepts.
get_top_display(**kwargs)[source]

Returns all concepts or collections that form the top-level of a display hierarchy. :return: A lst of concepts and collections.

Utils module

Utility functions for skosprovider_heritagedata.

skosprovider_heritagedata.utils.conceptscheme_from_uri(conceptscheme_uri)[source]

Read a SKOS Conceptscheme from a URI

Parameters:conceptscheme_uri (string) – URI of the conceptscheme.
Return type:skosprovider.skos.ConceptScheme
skosprovider_heritagedata.utils.text_(s, encoding='latin-1', errors='strict')[source]

If s is an instance of binary_type, return s.decode(encoding, errors), otherwise return s

skosprovider_heritagedata.utils.things_from_graph(graph, concept_scheme)[source]

Read concepts and collections from a graph.

Parameters:
Return type:

list

skosprovider_heritagedata.utils.uri_to_graph(uri)[source]
Parameters:uri (string) – URI where the RDF data can be found.
Return type:rdflib.Graph
Raises skosprovider.exceptions.ProviderUnavailableException:
 if the heritagedata.org services are down