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_region – dogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache). - change_cache_region(cache_region)[source]¶
Replaces the cache_region attribute.
Parameters: cache_region – dogpile.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.
- 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: resource – Resource object to remove from the cache.
oldman.store.datastore module¶
- class oldman.store.datastore.DataStore(model_manager, cache_region=None, accept_iri_generation_configuration=True, support_sparql=False)[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: - model_manager – TODO: describe!!!
- cache_region – dogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache). See ResourceCache for further details.
- accept_iri_generation_configuration – If False, the IRI generator cannot be configured by the user: it is imposed by the data store. Default to False.
- 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.
- create_model(class_name_or_iri, context_iri_or_payload, iri_generator=None, iri_prefix=None, iri_fragment=None, incremental_iri=False, context_file_path=None)[source]¶
TODO: comment. Convenience function
- delete(resource, attributes, former_types)[source]¶
End-users should not call it directly. Call oldman.Resource.delete() instead.
Parameters: - resource – Resource 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:
- regular attribute key-values ;
- 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.
- classmethod get_store(name)[source]¶
Gets a DataStore object by its name.
Parameters: name – store name. Returns: A ModelManager object.
- model_manager[source]¶
The ModelManager object.
TODO: update
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.
- save(resource, attributes, former_types)[source]¶
End-users should not call it directly. Call oldman.Resource.save() instead.
Parameters: - resource – Resource 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.
- support_sparql_filtering()[source]¶
Returns True if the datastore supports SPARQL queries (no update).
Note that in such a case, the sparql_filter() method is expected to be implemented.
oldman.store.http module¶
- class oldman.store.http.HttpDataStore(schema_graph=None, cache_region=None, session=None)[source]¶
Bases: oldman.store.datastore.DataStore
Read only. No search feature.
oldman.store.selector module¶
oldman.store.sparql module¶
- class oldman.store.sparql.SPARQLDataStore(data_graph, schema_graph=None, model_manager=None, 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_graph – rdflib.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_region – dogpile.cache.region.CacheRegion object. This object must already be configured. Defaults to None (no cache). See ResourceCache for further details.
TODO: explain the choice between schema_graph and resource_manager
- 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.
- 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.