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_graph – rdflib.Graph object contains all the schema triples.
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_graph – rdflib.Graph object containing all the schema triples.
- data_store – DataStore object. Supports CRUD operations on Resource objects.
- attr_extractor – OMAttributeExtractor 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:
- Its class IRI which can be retrieved from class_name_or_iri;
- Its JSON-LD context for mapping OMAttribute values to RDF triples;
- 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.
- context – dict, list or IRI that represents the JSON-LD context .
- iri_generator – IriGenerator 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:
- filter(types=None, hashless_iri=None, limit=None, eager=False, pre_cache_properties=None, **kwargs)[source]¶
- find_models_and_types(type_set)[source]¶
See oldman.management.registry.ModelRegistry.find_models_and_types().
- 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.
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:
- the IRI generator to use (the one of the first model);
- 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