oldman.storage.store package¶
Submodules¶
oldman.storage.store.cache module¶
-
class
oldman.storage.store.cache.ResourceCache(cache_region)[source]¶ Bases:
objectA
ResourceCacheobject cachesResourceobjects.It interfaces a
dogpile.cache.region.CacheRegionfront-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.CacheRegionobject. This object must already be configured. Defaults to None (no cache).-
cache_region¶ dogpile.cache.region.CacheRegionobject. May be None.
-
change_cache_region(cache_region)[source]¶ Replaces the cache_region attribute.
Parameters: cache_region – dogpile.cache.region.CacheRegionobject. May be None.
-
get_resource(iri, store_session)[source]¶ Gets a
Resourceobject from the cache.Parameters: iri – IRI of the resource. Returns: Resourceobject 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.CacheBackendobjects. In such a case, this method has no effect so entries must be removed explicitly from their keys.
-
remove_resource(resource)[source]¶ Removes a
Resourceobject from the cache.Indempotent (no problem if the
Resourceobject is not the cache). Does nothing if cache_region is None.Parameters: resource – Resourceobject 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.StoreRead 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.StoreA
SPARQLStoreis aStoreobject relying on a SPARQL 1.1 endpoint (Query and Update).Parameters: - data_graph –
rdflib.graph.Graphobject where all the non-schema resources are stored by default. - union_graph – Union of all the named graphs of a
rdflib.ConjunctiveGraphor ardflib.Dataset. Super-set of data_graph and may also include schema_graph. Defaults to data_graph. Read-only. - cache_region –
dogpile.cache.region.CacheRegionobject. This object must already be configured. Defaults to None (no cache). SeeResourceCachefor 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:
objectA
Storeobject manages CRUD operations onStoreResourceobjects.In the future, non-CRUD operations may also be supported.
Manages the cache (
ResourceCacheobject) ofStoreResourceobject.Parameters: - model_manager – TODO: describe!!!
- cache_region –
dogpile.cache.region.CacheRegionobject. This object must already be configured. Defaults to None (no cache). SeeResourceCachefor 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
UnsupportedDataStorageFeatureExceptionexception.Parameters: resource_iri – IRI of the Resourceobject.Returns: True if exists.
-
filter(store_session, types=None, hashless_iri=None, limit=None, eager=True, pre_cache_properties=None, **kwargs)[source]¶ Finds the
Resourceobjects 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 (
Resourceobjects) 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
Resourceobjects.
-
first(store_session, types=None, hashless_iri=None, eager_with_reversed_attributes=True, pre_cache_properties=None, **kwargs)[source]¶ Gets the first
Resourceobject 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
Resourceobjects that do not have reversed attributes. Defaults to True. - pre_cache_properties – List of RDF ObjectProperties to pre-cache eagerly.
Their values (
Resourceobjects) are loaded and added to the cache. Defaults to []. If given, eager must be True. Disabled if there is no cache.
Returns: A
Resourceobject 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
UnsupportedDataStorageFeatureExceptionexception.Parameters: class_iri – RDFS class IRI. Returns: Incremented number.
-
get(store_session, iri, types=None, eager_with_reversed_attributes=True)[source]¶ Gets the
Resourceobject having the given IRI.The kwargs dict can contains regular attribute key-values.
When types are given, they are then checked. An
OMClassInstanceErroris 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
StoreResourceobject or None if no resource has been found.
-
classmethod
get_store(name)[source]¶ Gets a
DataStoreobject by its name.Parameters: name – store name. Returns: A ModelManagerobject.
-
model_manager¶ The
ModelManagerobject.TODO: update
Necessary for creating new
StoreResourceobjects and accessing toModelobjects.
-
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¶ ResourceCacheobject.
-
sparql_filter(store_session, query)[source]¶ Finds the
Resourceobjects matching a given query.Raises an
UnsupportedDataStorageFeatureExceptionexception 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 Resourceobjects.