oldman.store package

Submodules

oldman.store.cache module

class oldman.store.cache.ResourceCache(cache_region)[source]

Bases: object

A ResourceCache object caches Resource objects.

It interfaces a dogpile.cache.region.CacheRegion front-end object. If not None, cache_region must be already configured, i.e. mapped to a back-end (like Memcache or Redis). See the official list of back-ends supported by dogpile.cache.

When cache_region is None, no effective caching is done. However, methods get_resource(), set_resource() and remove_resource() can still safely be called. They just have no effect.

Parameters:cache_regiondogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache).
cache_region[source]

dogpile.cache.region.CacheRegion object. May be None.

change_cache_region(cache_region)[source]

Replaces the cache_region attribute.

Parameters:cache_regiondogpile.cache.region.CacheRegion object. May be None.
get_resource(id)[source]

Gets a Resource object from the cache.

Parameters:id – IRI of the resource.
Returns:Resource object or None if not found.
invalidate_cache()[source]

See dogpile.cache.region.CacheRegion.invalidate().

Cache invalidation

Please note that this method is not supported by some dogpile.cache.api.CacheBackend objects. In such a case, this method has no effect so entries must be removed explicitly from their keys.

is_active()[source]
Returns:True if the cache_region is active.
remove_resource(resource)[source]

Removes a Resource object from the cache.

Indempotent (no problem if the Resource object is not the cache). Does nothing if cache_region is None.

Parameters:resourceResource object to remove from the cache.
remove_resource_from_id(id)[source]

remove_resource() is usually preferred.

Indempotent and does nothing if cache_region is None.

Parameters:id – IRI of the resource to remove from the cache.
set_resource(resource)[source]

Adds or updates a Resource object in the cache.

Its key is its ìd.

Parameters:resourceResource object to add to the cache (or update).

oldman.store.datastore module

class oldman.store.datastore.DataStore(cache_region=None)[source]

Bases: object

A DataStore object manages CRUD operations on Resource objects.

In the future, non-CRUD operations may also be supported.

Manages the cache (ResourceCache object) of Resource object.

A ResourceManager object must be assigned after instantiation of this object.

Parameters:cache_regiondogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache). See ResourceCache for further details.
check_and_repair_counter(class_iri)[source]

Checks the counter of a given RDFS class and repairs (inits) it if needed.

Parameters:class_iri – RDFS class IRI.
delete(resource, attributes, former_types)[source]

End-users should not call it directly. Call oldman.Resource.delete() instead.

Parameters:
  • resourceResource object.
  • attributes – Ordered list of OMAttribute objects.
  • former_types – List of RDFS class IRIs previously saved.
exists(resource_iri)[source]

Tests if the IRI of the resource is present in the data_store.

May raise an UnsupportedDataStorageFeatureException exception.

Parameters:resource_iri – IRI of the Resource object.
Returns:True if exists.
filter(types=None, hashless_iri=None, limit=None, eager=False, pre_cache_properties=None, **kwargs)[source]

Finds the Resource objects matching the given criteria.

The kwargs dict can contains:

  1. regular attribute key-values ;
  2. the special attribute id. If given, get() is called.
Parameters:
  • types – IRIs of the RDFS classes filtered resources must be instance of. Defaults to None.
  • hashless_iri – Hash-less IRI of filtered resources. Defaults to None.
  • limit – Upper bound on the number of solutions returned (e.g. SPARQL LIMIT). Positive integer. Defaults to None.
  • eager – If True loads all the Resource objects within the minimum number of queries (e.g. one single SPARQL query). Defaults to False (lazy).
  • pre_cache_properties – List of RDF ObjectProperties to pre-cache eagerly. Their values (Resource objects) are loaded and added to the cache. Defaults to []. If given, eager must be True. Disabled if there is no cache.
Returns:

A generator (if lazy) or a list (if eager) of Resource objects.

generate_instance_number(class_iri)[source]

Generates a new incremented number for a given RDFS class IRI.

May raise an UnsupportedDataStorageFeatureException exception.

Parameters:class_iri – RDFS class IRI.
Returns:Incremented number.
get(id=None, types=None, hashless_iri=None, eager_with_reversed_attributes=True, **kwargs)[source]

Gets the first Resource object matching the given criteria.

The kwargs dict can contains regular attribute key-values.

When id is given, types are then checked. An OMClassInstanceError is raised if the resource is not instance of these classes. Other criteria are not checked.

Parameters:
  • id – IRI of the resource. Defaults to None.
  • types – IRIs of the RDFS classes filtered resources must be instance of. Defaults to None.
  • hashless_iri – Hash-less IRI of filtered resources. Defaults to None.
  • eager_with_reversed_attributes – Allow to Look eagerly for reversed RDF properties. May cause some overhead for some Resource objects that do not have reversed attributes. Defaults to True.
Returns:

A Resource object or None if no resource has been found.

manager[source]

The ResourceManager object.

Necessary for creating new Resource objects and accessing to Model objects.

reset_instance_counter(class_iri)[source]

Reset the counter related to a given RDFS class.

For test purposes only.

Parameters:class_iri – RDFS class IRI.
resource_cache[source]

ResourceCache object.

save(resource, attributes, former_types)[source]

End-users should not call it directly. Call oldman.Resource.save() instead.

Parameters:
  • resourceResource object.
  • attributes – Ordered list of OMAttribute objects.
  • former_types – List of RDFS class IRIs previously saved.
sparql_filter(query)[source]

Finds the Resource objects matching a given query.

Raises an UnsupportedDataStorageFeatureException exception if the SPARQL protocol is not supported by the concrete data_store.

Parameters:query – SPARQL SELECT query where the first variable assigned corresponds to the IRIs of the resources that will be returned.
Returns:A generator of Resource objects.

oldman.store.sparql module

class oldman.store.sparql.SPARQLDataStore(data_graph, union_graph=None, cache_region=None)[source]

Bases: oldman.store.datastore.DataStore

A SPARQLDataStore is a DataStore object relying on a SPARQL 1.1 endpoint (Query and Update).

Parameters:
  • data_graphrdflib.graph.Graph object where all the non-schema resources are stored by default.
  • union_graph – Union of all the named graphs of a rdflib.ConjunctiveGraph or a rdflib.Dataset. Super-set of data_graph and may also include schema_graph. Defaults to data_graph. Read-only.
  • cache_regiondogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache). See ResourceCache for further details.
check_and_repair_counter(class_iri)[source]

Checks the counter of a given RDFS class and repairs (inits) it if needed.

Parameters:class_iri – RDFS class IRI.
exists(id)[source]
extract_prefixes(other_graph)[source]

Adds the RDF prefix (namespace) information from an other graph to the namespace of the data_graph. :param other_graph: rdflib.graph.Graph that some prefix information.

generate_instance_number(class_iri)[source]

Needed for generating incremental IRIs.

reset_instance_counter(class_iri)[source]

Reset the counter related to a given RDFS class.

For test purposes only.

Parameters:class_iri – RDFS class IRI.
sparql_filter(query)[source]

Finds the Resource objects matching a given query.

Parameters:query – SPARQL SELECT query where the first variable assigned corresponds to the IRIs of the resources that will be returned.
Returns:A generator of Resource objects.

Module contents