oldman.model package¶
Submodules¶
oldman.model.ancestry module¶
- class oldman.model.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.model.attribute module¶
- class oldman.model.attribute.OMAttribute(metadata, value_format)[source]¶
Bases: object
An OMAttribute object corresponds to a JSON-LD term that refers to a RDF property.
TODO: update the documentation. No direct access to the resource_manager anymore (indirect through the resource).
Technically, the name of the OMAttribute object is a JSON-LD term, namely “a short-hand string that expands to an IRI or a blank node identifier” (cf. the JSON-LD standard) which corresponds here to a RDF property (see OMProperty).
In JSON-LD, the same RDF property may correspond to multiple JSON-LD terms that have different metadata. For instance, a foaf:Person resource may have two attributes for its bio in English and in French. These attributes have two different languages but use the same property bio:olb. Look at the quickstart example to see it in practice.
An OMAttribute object manages the values of every Resource object that depends on a given Model object.
Each value may be :
- None;
- The Python equivalent for a RDF literal (double, string, date, etc.);
- An IRI;
- A collection (set, list and dict) of these types.
Parameters: - metadata – OMAttributeMetadata object.
- value_format – ValueFormat object that validates the format of values and converts RDF values into regular Python objects.
- check_validity(resource, is_end_user=True)[source]¶
Raises an OMEditError exception if the attribute value assigned to a resource is invalid.
Parameters: - resource – Resource object.
- is_end_user – False when an authorized user (not a regular end-user) wants to force some rights. Defaults to True.
- check_value(value)[source]¶
Checks a new when assigned.
Raises an oldman.exception.OMAttributeTypeCheckError exception if the value is invalid.
Parameters: value – collection or atomic value.
- diff(resource)[source]¶
Gets out the former value that has been replaced.
TODO: update this comment
Parameters: resource – Resource object. Returns: The former and new attribute values.
- get(resource)[source]¶
Gets the attribute value of a resource.
Parameters: resource – Resource object. Returns: Atomic value or a generator.
- get_lightly(resource)[source]¶
Gets the attribute value of a resource in a lightweight manner.
By default, behaves exactly like get(). See the latter function for further details.
- has_value(resource)[source]¶
Tests if the resource attribute has a non-None value.
Parameters: resource – Resource object. Returns: False if the value is None.
- is_valid(resource, is_end_user=True)[source]¶
Tests if the attribute value assigned to a resource is valid.
See check_validity() for further details.
Returns: False if the value assigned to the resource is invalid and True otherwise.
- receive_storage_ack(resource)[source]¶
Clears the former value that has been replaced.
TODO: update this description.
Parameters: resource – Resource object.
- set(resource, value)[source]¶
Sets the attribute value of a resource.
Parameters: - resource – Resource object.
- value – Its value for this attribute.
- to_nt(resource)[source]¶
Converts its current attribute value to N-Triples (NT) triples.
Relies on value_to_nt().
Parameters: resource – Resource object. Returns: N-Triples serialization of its attribute value.
- update_from_graph(resource, sub_graph, initial=False)[source]¶
Updates a resource attribute value by extracting the relevant information from a RDF graph.
Parameters: - resource – Resource object.
- sub_graph – rdflib.Graph object containing the value to extract.
- initial – True when the value is directly from the datastore. Defaults to False.
- value_format[source]¶
ValueFormat object that validates the format of values and converts RDF values into regular Python objects.
- class oldman.model.attribute.OMAttributeMetadata¶
Bases: tuple
OMAttributeMetadata(name, property, language, jsonld_type, container, reversed)
- container¶
Alias for field number 4
- jsonld_type¶
Alias for field number 3
- language¶
Alias for field number 2
- name¶
Alias for field number 0
- property¶
Alias for field number 1
- reversed¶
Alias for field number 5
- class oldman.model.attribute.ObjectOMAttribute(metadata, value_format)[source]¶
Bases: oldman.model.attribute.OMAttribute
An ObjectOMAttribute object is an OMAttribute object that depends on an owl:ObjectProperty.
oldman.model.converter module¶
- class oldman.model.converter.EquivalentModelConverter(client_model, store_model)[source]¶
Bases: oldman.model.converter.DirectMappingModelConverter
TODO: describe
oldman.model.manager module¶
- class oldman.model.manager.ClientModelManager(resource_manager, **kwargs)[source]¶
Bases: oldman.model.manager.ModelManager
Client ModelManager.
Has access to the resource_manager. In charge of the conversion between and store and client models.
- class oldman.model.manager.ModelManager(schema_graph=None, attr_extractor=None, oper_extractor=None, declare_default_operation_functions=True)[source]¶
Bases: object
TODO: update this documentation
The model_manager creates and registers Model objects.
Internally, it owns a ModelRegistry object.
Parameters: - schema_graph – rdflib.Graph object containing all the schema triples.
- data_store – DataStore object.
- attr_extractor – OMAttributeExtractor object that will extract OMAttribute for generating new Model objects. Defaults to a new instance of OMAttributeExtractor.
- oper_extractor – TODO: describe.
- declare_default_operation_functions – TODO: describe.
- create_model(class_name_or_iri, context_iri_or_payload, data_store, iri_prefix=None, iri_fragment=None, iri_generator=None, untyped=False, incremental_iri=False, is_default=False, context_file_path=None)[source]¶
Creates a Model object.
TODO: remove data_store from the constructor!
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_iri_or_payload – 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.
- context_file_path – TODO: describe.
- find_models_and_types(type_set)[source]¶
See oldman.resource.registry.ModelRegistry.find_models_and_types().
oldman.model.model module¶
- class oldman.model.model.ClientModel(resource_manager, name, class_iri, ancestry_iris, context, om_attributes, id_generator, operations=None, local_context=None)[source]¶
Bases: oldman.model.model.Model
TODO: describe.
TODO: further study this specific case
- all(limit=None, eager=False)[source]¶
Finds every Resource object that is instance of its RDFS class.
Parameters: - limit – Upper bound on the number of solutions returned (SPARQL LIMIT). Positive integer. Defaults to None.
- eager – If True loads all the Resource objects within one single SPARQL query. Defaults to False (lazy).
Returns: A generator of Resource objects.
- create(id=None, hashless_iri=None, collection_iri=None, **kwargs)[source]¶
Creates a new resource and saves it.
See new() for more details.
- filter(hashless_iri=None, limit=None, eager=False, pre_cache_properties=None, **kwargs)[source]¶
Finds the Resource objects matching the given criteria.
The class_iri attribute is added to the types.
See oldman.resource.finder.ResourceFinder.filter() for further details.
- get(id=None, hashless_iri=None, **kwargs)[source]¶
Gets the first Resource object matching the given criteria.
The class_iri attribute is added to the types. Also looks if reversed attributes should be considered eagerly.
See oldman.store.datastore.DataStore.get() for further details.
- class oldman.model.model.Model(name, class_iri, ancestry_iris, context, om_attributes, id_generator, operations=None, local_context=None)[source]¶
Bases: object
A Model object represents a RDFS class on the Python side.
TODO: update this documentation
It gathers OMAttribute objects and Python methods which are made available to Resource objects that are instances of its RDFS class.
It also creates and retrieves Resource objects that are instances of its RDFS class. It manages an IriGenerator object.
Model creation
Model objects are normally created by a ResourceManager object. Please use the oldman.resource.manager.ResourceManager.create_model() method for creating new Model objects.
Parameters: - manager – ResourceManager object that has created this model.
- name – Model name. Usually corresponds to a JSON-LD term or to a class IRI.
- class_iri – IRI of the RDFS class represented by this Model object.
- ancestry_iris – ancestry of the attribute class_iri. Each instance of class_iri is also instance of these classes.
- context – An IRI, a list or a dict that describes the JSON-LD context. See http://www.w3.org/TR/json-ld/#the-context for more details.
- om_attributes – dict of OMAttribute objects. Keys are their names.
- id_generator – IriGenerator object that generates IRIs from new Resource objects.
- methods – dict of Python functions that takes as first argument a Resource object. Keys are the method names. Defaults to {}.
- operations – TODO: describe.
- local_context – TODO: describe.
- access_attribute(name)[source]¶
Gets an OMAttribute object.
Used by the Resource class but an end-user should not need to call it.
Parameters: name – Name of the attribute. Returns: The corresponding OMAttribute object.
- context[source]¶
An IRI, a list or a dict that describes the JSON-LD context. See http://www.w3.org/TR/json-ld/#the-context for more details.
Official context that will be included in the representation.
- generate_iri(**kwargs)[source]¶
Generates a new IRI.
Used by the Resource class but an end-user should not need to call it.
Returns: A new IRI.
- is_subclass_of(model)[source]¶
Returns True if its RDFS class is a sub-class (rdfs:subClassOf) of the RDFS class of another model.
Parameters: model – Model object to compare with. Returns: True if is a sub-class of the other model, False otherwise.
oldman.model.operation module¶
TODO: explain
- class oldman.model.operation.Operation(http_method, excepted_type, returned_type, function, name)[source]¶
Bases: object
TODO: describe
- oldman.model.operation.append_to_hydra_collection(collection_resource, new_resources=None, graph=None, **kwargs)[source]¶
TODO: improve the mechanism of operation
oldman.model.property module¶
- class oldman.model.property.OMProperty(property_iri, supporter_class_iri, is_required=False, read_only=False, write_only=False, reversed=False, cardinality=None, property_type=None, domains=None, ranges=None, link_class_iri=None)[source]¶
Bases: object
An OMProperty object represents the support of a RDF property by a RDFS class.
TODO: check this documentation after the removal of the resource_manager.
It gathers some OMAttribute objects (usually one).
An OMProperty object is in charge of generating its OMAttribute objects according to the metadata that has been extracted from the schema and JSON-LD context.
A property can be reversed: the Resource object to which the OMAttribute objects will be (indirectly) attached is then the object of this property, not its subject (?o ?p ?s).
Consequently, two OMProperty objects can refer to the same RDF property when one is reversed while the second is not.
Parameters: - property_iri – IRI of the RDF property.
- supporter_class_iri – IRI of the RDFS class that supports the property.
- is_required – If True instances of the supporter class must assign a value to this property for being valid. Defaults to False.
- read_only – If True, the value of the property cannot be modified by a regular end-user. Defaults to False.
- write_only – If True, the value of the property cannot be read by a regular end-user. Defaults to False.
- reversed – If True, the property is reversed. Defaults to False.
- cardinality – Defaults to None. Not yet supported.
- property_type – String. In OWL, a property is either a DatatypeProperty or an ObjectProperty. Defaults to None (unknown).
- domains – Set of class IRIs that are declared as the RDFS domain of the property. Defaults to set().
- ranges – Set of class IRIs that are declared as the RDFS range of the property. Defaults to set().
- link_class_iri – TODO: describe.
- add_attribute_metadata(name, jsonld_type=None, language=None, container=None, reversed=False)[source]¶
Adds metadata about a future OMAttribute object.
Parameters: - name – JSON-LD term representing the attribute.
- jsonld_type – JSON-LD type (datatype IRI or JSON-LD keyword). Defaults to None.
- language – Defaults to None.
- container – JSON-LD container (“@set”, “@list”, “@language” or “@index”). Defaults to None.
- reversed – True if the object and subject in RDF triples should be reversed. Defaults to False.
- add_domain(domain)[source]¶
Declares a RDFS class as part of the domain of the property.
Parameters: domain – IRI of RDFS class.
- add_range(p_range)[source]¶
Declares a RDFS class as part of the range of the property.
Parameters: p_range – IRI of RDFS class.
- default_datatype[source]¶
IRI that is the default datatype of the property.
May be None (if not defined or if the property is an owl:ObjectProperty)
- generate_attributes(attr_format_selector)[source]¶
Generates its OMAttribute objects.
Can be called only once. When called a second time, raises an OMAlreadyGeneratedAttributeError exception.
Parameters: attr_format_selector – ValueFormatSelector object.
oldman.model.registry module¶
- class oldman.model.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_name_or_iri)[source]¶
Gets a Model object.
Parameters: class_name_or_iri – Name or IRI of a RDFS class Returns: A Model object or None if not found