oldman.management package

oldman.management.ancestry module

class oldman.management.ancestry.ClassAncestry(child_class_iri, schema_graph)[source]

Bases: object

Ancestry of a given RDFS class.

Parameters:
  • child_class_iri – IRI of the child RDFS class.
  • schema_graphrdflib.Graph object contains all the schema triples.
bottom_up[source]

Ancestry list starting from the child.

child[source]

Child of the ancestry.

parents(class_iri)[source]

Finds the parents of a given class in the ancestry.

Parameters:class_iri – IRI of the RDFS class.
Returns:List of class IRIs
top_down[source]

Reverse of the bottom_up attribute.

oldman.management.manager module

class oldman.management.manager.ResourceManager(schema_graph, data_store, attr_extractor=None, manager_name='default')[source]

Bases: object

The resource_manager is the central object of this OLDM.

It gives access to the DataStore object and creates Model objects. It also creates, retrieves and caches Resource objects.

Internally, it owns a ModelRegistry object.

Parameters:
  • schema_graphrdflib.Graph object containing all the schema triples.
  • data_storeDataStore object. Supports CRUD operations on Resource objects.
  • attr_extractorOMAttributeExtractor object that will extract OMAttribute for generating new Model objects. Defaults to a new instance of OMAttributeExtractor.
  • manager_name – Name of this manager. Defaults to “default”. This name must be unique.
create(id=None, types=None, hashless_iri=None, **kwargs)[source]

Creates a new resource and save it in the data_store.

See new() for more details.

create_model(class_name_or_iri, context, iri_generator=None, iri_prefix=None, iri_fragment=None, incremental_iri=False)[source]

Creates a Model object.

To create it, they are three elements to consider:

  1. Its class IRI which can be retrieved from class_name_or_iri;
  2. Its JSON-LD context for mapping OMAttribute values to RDF triples;
  3. The IriGenerator object that generates IRIs from new Resource objects.

The IriGenerator object is either:

  • directly given: iri_generator;
  • created from the parameters iri_prefix, iri_fragment and incremental_iri.
Parameters:
  • class_name_or_iri – IRI or JSON-LD term of a RDFS class.
  • contextdict, list or IRI that represents the JSON-LD context .
  • iri_generatorIriGenerator object. If given, other iri_* parameters are ignored.
  • iri_prefix – Prefix of generated IRIs. Defaults to None. If is None and no iri_generator is given, a BlankNodeIriGenerator is created.
  • iri_fragment – IRI fragment that is added at the end of generated IRIs. For instance, “me” adds “#me” at the end of the new IRI. Defaults to None. Has no effect if iri_prefix is not given.
  • incremental_iri – If True an IncrementalIriGenerator is created instead of a RandomPrefixedIriGenerator. Defaults to False. Has no effect if iri_prefix is not given.
Returns:

A new Model object.

data_store[source]

DataStore object. Supports CRUD operations on :class:`~oldman.resource.Resource objects`.

declare_method(method, name, class_iri)[source]

Attaches a method to the Resource objects that are instances of a given RDFS class.

Like in Object-Oriented Programming, this method can be overwritten by attaching a homonymous method to a class that has a higher inheritance priority (such as a sub-class).

To benefit from this method (or an overwritten one), Resource objects must be associated to a Model that corresponds to the RDFS class or to one of its subclasses.

This method can only be used before the creation of any model (except the default one).

Parameters:
  • method – Python function that takes as first argument a Resource object.
  • name – Name assigned to this method.
  • class_iri – Targetted RDFS class. If not overwritten, all the instances (Resource objects) should inherit this method.
filter(types=None, hashless_iri=None, limit=None, eager=False, pre_cache_properties=None, **kwargs)[source]

See oldman.store.datastore.DataStore.filter().

find_models_and_types(type_set)[source]

See oldman.management.registry.ModelRegistry.find_models_and_types().

get(id=None, types=None, hashless_iri=None, eager_with_reversed_attributes=True, **kwargs)[source]

See oldman.store.datastore.DataStore.get().

classmethod get_manager(name)[source]

Gets a ResourceManager object by its name.

Parameters:name – manager name.
Returns:A ResourceManager object.
include_reversed_attributes[source]

Is True if at least one of its models use some reversed attributes.

name[source]

Name of this manager. The manager can be retrieved from its name by calling the class method get_manager().

new(id=None, types=None, hashless_iri=None, **kwargs)[source]

Creates a new Resource object without saving it in the data_store.

The kwargs dict can contains regular attribute key-values that will be assigned to OMAttribute objects.

Parameters:
  • id – IRI of the new resource. Defaults to None. If not given, the IRI is generated by the IRI generator of the main model.
  • types – IRIs of RDFS classes the resource is instance of. Defaults to None. Note that these IRIs are used to find the models of the resource (see find_models_and_types() for more details).
  • hashless_iri – hash-less IRI that MAY be considered when generating an IRI for the new resource. Defaults to None. Ignored if id is given.
Returns:

A new Resource object.

sparql_filter(query)[source]

See oldman.store.datastore.DataStore.sparql_filter().

oldman.management.registry module

class oldman.management.registry.ModelRegistry[source]

Bases: object

A ModelRegistry object registers the Model objects.

Its main function is to find and order models from a set of class IRIs (this ordering is crucial when creating new Resource objects). See find_models_and_types() for more details.

find_models_and_types(type_set)[source]

Finds the leaf models from a set of class IRIs and orders them. Also returns an ordered list of the RDFS class IRIs that come from type_set or were deduced from it.

Leaf model ordering is important because it determines:

  1. the IRI generator to use (the one of the first model);
  2. method inheritance priorities between leaf models.

Resulting orderings are cached.

Parameters:type_set – Set of RDFS class IRIs.
Returns:An ordered list of leaf Model objects and an ordered list of RDFS class IRIs.
get_model(class_iri)[source]

Gets a Model object.

Parameters:class_iri – IRI of a RDFS class
Returns:A Model object or None if not found
has_specific_models()[source]
Returns:True if contains other models than the default one.
model_names[source]

Names of the registered models.

register(model, is_default=False)[source]

Registers a Model object.

Parameters:
  • model – the Model object to register.
  • is_default – If True, sets the model as the default model. Defaults to False.
unregister(model)[source]

Un-registers a Model object.

Parameters:model – the Model object to remove from the registry.