API Documentation

Providers module

This module implements a skosprovider.providers.VocabularyProvider for Atramhasis

class skosprovider_atramhasis.providers.AtramhasisProvider(metadata, **kwargs)[source]

A provider that can work with the Atramhasis REST services

base_url = None

Base URL of an Atramhasis instance.

expand(id_)[source]

Expand a concept or collection to all it’s narrower concepts.

This method should recurse and also return narrower concepts of 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.

If the id passed belongs to a skosprovider.skos.Collection, the id of the collection itself must not be present in the return value In this case the return value includes all the member concepts and their narrower concepts.

Parameters

id – A concept or collection id.

Return type

A list of id’s or False if the concept or collection doesn’t exist.

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.

# 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'})

# Find anything that has a label of church.
# Preferentially display a label in Dutch.
provider.find({'label': 'church'}, language='nl')

# Find anything that has a match with an external concept
# Preferentially display a label in Dutch.
provider.find({
    'matches': {
        'uri': 'http://id.python.org/different/types/of/trees/nr/1/the/larch'
    }}, language='nl')

# Find anything that has a label of lariks with a close match to an external concept
# Preferentially display a label in Dutch.
provider.find({
    'label': 'lariks',
    'matches': {
        'type': 'close',
        'uri': 'http://id.python.org/different/types/of/trees/nr/1/the/larch'
    }}, language='nl')
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 or None, 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.

    • matches: Search only for concepts having a match to a certain

      external concept. Since collections can’t have matches, this automatically excludes collections. The argument with two keys:

      • uri: The uri of the concept to match. Required.

      • type: The type of match, see matchtypes for the full list of options.

  • language (string) – Optional. If present, it should be a language-tag. This language-tag is passed on to the underlying providers and used when selecting the label to display for each concept.

  • sort (string) – Optional. If present, it should either be id, label or sortlabel. The sortlabel option means the providers should take into account any sortLabel if present, if not it will fallback to a regular label to sort on.

  • sort_order (string) – Optional. What order to sort in: asc or desc. Defaults to asc

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 language parameter, the default language of the provider and finally falls back to en.

get_all(**kwargs)[source]

Returns all concepts and collections in this provider.

Parameters
  • language (string) – Optional. If present, it should be a language-tag. This language-tag is passed on to the underlying providers and used when selecting the label to display for each concept.

  • sort (string) – Optional. If present, it should either be id, label or sortlabel. The sortlabel option means the providers should take into account any sortLabel if present, if not it will fallback to a regular label to sort on.

  • sort_order (string) – Optional. What order to sort in: asc or desc. Defaults to asc

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 language parameter, the default language of the provider and finally falls back to en.

get_by_id(id_)[source]

Get all information on a concept or collection, based on id.

Providers should assume that all id’s passed are strings. If a provider knows that internally it uses numeric identifiers, it’s up to the provider to do the typecasting. Generally, this should not be done by changing the id’s themselves (eg. from int to str), but by doing the id comparisons in a type agnostic way.

Since this method could be used to find both concepts and collections, it’s assumed that there are no id collisions between concepts and collections.

Return type

skosprovider.skos.Concept or skosprovider.skos.Collection or False if the concept or collection is unknown to the provider.

get_by_uri(uri)[source]

Get all information on a concept or collection, based on a URI.

Return type

skosprovider.skos.Concept or skosprovider.skos.Collection or False if the concept or collection is unknown to the provider.

get_children_display(id_, **kwargs)[source]

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

Parameters
  • language (string) – Optional. If present, it should be a language-tag. This language-tag is passed on to the underlying providers and used when selecting the label to display for each concept.

  • sort (string) – Optional. If present, it should either be id, label or sortlabel. The sortlabel option means the providers should take into account any sortLabel if present, if not it will fallback to a regular label to sort on.

  • sort_order (string) – Optional. What order to sort in: asc or desc. Defaults to asc

  • id (str) – A concept or collection id.

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 language parameter, the default language of the provider and finally falls back to en.

get_top_concepts(**kwargs)[source]

Returns all top-level concepts in this provider.

Top-level concepts are concepts that have no broader concepts themselves. They might have narrower concepts, but this is not mandatory.

Parameters
  • language (string) – Optional. If present, it should be a language-tag. This language-tag is passed on to the underlying providers and used when selecting the label to display for each concept.

  • sort (string) – Optional. If present, it should either be id, label or sortlabel. The sortlabel option means the providers should take into account any sortLabel if present, if not it will fallback to a regular label to sort on.

  • sort_order (string) – Optional. What order to sort in: asc or desc. Defaults to asc

Returns

A lst of concepts, NOT 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 language parameter, the default language of the provider and finally falls back to en.

get_top_display(**kwargs)[source]

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

As opposed to the get_top_concepts(), this method can possibly return both concepts and collections.

Parameters
  • language (string) – Optional. If present, it should be a language-tag. This language-tag is passed on to the underlying providers and used when selecting the label to display for each concept.

  • sort (string) – Optional. If present, it should either be id, label or sortlabel. The sortlabel option means the providers should take into account any sortLabel if present, if not it will fallback to a regular label to sort on.

  • sort_order (string) – Optional. What order to sort in: asc or desc. Defaults to asc

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 language parameter, the default language of the provider and finally falls back to en.

scheme_id = None

Identifier of the ConceptScheme this provider is managing.

session = None

The requests.Session being used to make HTTP requests.

Utils module

Utility functions for skosprovider_atramhasis.

skosprovider_atramhasis.utils.dict_to_thing(data_dict)[source]

Transform a dict into a skosprovider.skos.Concept or skosprovider.skos.Collection .

If the argument passed is already a skosprovider.skos.Concept or skosprovider.skos.Collection, this method just returns the argument.

skosprovider_atramhasis.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

Cache_utils module

Utility functions for chaching in skosprovider_atramhasis.