oldman.storage.store package¶
Submodules¶
oldman.storage.store.cache module¶
-
class
oldman.storage.store.cache.
ResourceCache
(cache_region)[source]¶ Bases:
object
A
ResourceCache
object cachesResource
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()
andremove_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).-
cache_region
¶ dogpile.cache.region.CacheRegion
object. May be None.
-
change_cache_region
(cache_region)[source]¶ Replaces the cache_region attribute.
Parameters: cache_region – dogpile.cache.region.CacheRegion
object. May be None.
-
get_resource
(iri, store_session)[source]¶ Gets a
Resource
object from the cache.Parameters: iri – 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.storage.store.http module¶
-
class
oldman.storage.store.http.
HttpStore
(schema_graph=None, cache_region=None, http_session=None)[source]¶ Bases:
oldman.storage.store.store.Store
Read only. No search feature.
oldman.storage.store.sparql module¶
-
class
oldman.storage.store.sparql.
SparqlStore
(data_graph, schema_graph=None, model_manager=None, union_graph=None, cache_region=None)[source]¶ Bases:
oldman.storage.store.store.Store
A
SPARQLStore
is aStore
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 ardflib.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). SeeResourceCache
for further details.
TODO: complete
-
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.
- data_graph –
oldman.storage.store.store module¶
-
class
oldman.storage.store.store.
Store
(model_manager, cache_region=None, accept_iri_generation_configuration=True, support_sparql=False)[source]¶ Bases:
object
A
Store
object manages CRUD operations onStoreResource
objects.In the future, non-CRUD operations may also be supported.
Manages the cache (
ResourceCache
object) ofStoreResource
object.Parameters: - model_manager – TODO: describe!!!
- cache_region –
dogpile.cache.region.CacheRegion
object. This object must already be configured. Defaults to None (no cache). SeeResourceCache
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
-
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
(store_session, types=None, hashless_iri=None, limit=None, eager=True, 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 iri. If given,
get()
is called.
TODO: UPDATE THE COMMENT!
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 True.
- 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.
-
first
(store_session, types=None, hashless_iri=None, eager_with_reversed_attributes=True, pre_cache_properties=None, **kwargs)[source]¶ Gets the first
Resource
object matching the given criteria.The kwargs dict can contains regular attribute key-values.
TODO: UPDATE THE COMMENT!
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.
- 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. - 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
Resource
object or None if no resource has been found.
-
flush
(resources_to_update, resources_to_delete, is_end_user)[source]¶ TODO: explain :param new_resources: :param resources_to_update: :param resources_to_delete: :return:
-
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
(store_session, iri, types=None, eager_with_reversed_attributes=True)[source]¶ Gets the
Resource
object having the given IRI.The kwargs dict can contains regular attribute key-values.
When types are given, they are then checked. An
OMClassInstanceError
is raised if the resource is not instance of these classes.Parameters: - iri – IRI of the resource. Defaults to None.
- types – IRIs of the RDFS classes filtered resources must be instance of. Defaults to None.
Returns: A
StoreResource
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
¶ The
ModelManager
object.TODO: update
Necessary for creating new
StoreResource
objects and accessing toModel
objects.
-
name
¶ Randomly generated name. Useful for serializing resources.
-
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
¶ ResourceCache
object.
-
sparql_filter
(store_session, 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.