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_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.model.attribute module

class oldman.model.attribute.Entry(saved_value=None)[source]

Bases: object

Mutable.

TODO: describe

clone()[source]
current_value[source]
diff()[source]

TODO: explain

has_changed()[source]

True if the value differs from the stored one

receive_storage_ack()[source]

TODO: explain

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:
  • metadataOMAttributeMetadata object.
  • value_formatValueFormat 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:
  • resourceResource object.
  • is_end_userFalse 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.
container[source]

JSON-LD container (“@set”, “@list”, “@language” or “@index”). May be None.

diff(resource)[source]

Gets out the former value that has been replaced.

TODO: update this comment

Parameters:resourceResource object.
Returns:The former and new attribute values.
get(resource)[source]

Gets the attribute value of a resource.

Parameters:resourceResource object.
Returns:Atomic value or a generator.
get_entry(resource)[source]

TODO: describe. Clearly not for end-users!!!

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_changed(resource)[source]
Parameters:resourceResource object.
has_value(resource)[source]

Tests if the resource attribute has a non-None value.

Parameters:resourceResource object.
Returns:False if the value is None.
is_read_only[source]

True if the property cannot be modified by regular end-users.

is_required[source]

True if its property is required.

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.
is_write_only[source]

True if the property cannot be accessed by regular end-users.

jsonld_type[source]

JSON-LD type (datatype IRI or JSON-LD keyword). May be None.

language[source]

Its language if localized.

name[source]

Its name as an attribute.

om_property[source]

OMProperty to which it belongs.

other_attributes[source]

Other OMAttribute objects of the same property.

receive_storage_ack(resource)[source]

Clears the former value that has been replaced.

TODO: update this description.

Parameters:resourceResource object.
reversed[source]

True if the object and subject in RDF triples should be reversed.

set(resource, value)[source]

Sets the attribute value of a resource.

Parameters:
  • resourceResource object.
  • value – Its value for this attribute.
set_entry(resource, entry)[source]

TODO: describe. Clearly not for end-users!!!

to_nt(resource)[source]

Converts its current attribute value to N-Triples (NT) triples.

Relies on value_to_nt().

Parameters:resourceResource 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:
  • resourceResource object.
  • sub_graphrdflib.Graph object containing the value to extract.
  • initialTrue 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.

value_to_nt(value)[source]

Converts value(s) to N-Triples (NT) triples.

Parameters:value – Value of property.
Returns:N-Triples serialization of this value.
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.

get(resource)[source]

See get().

Returns:Resource object or a generator of Resource objects.
get_lightly(resource)[source]

Gets the attribute value of a resource in a lightweight manner.

By contrast with get() only IRIs are returned, not Resource objects.

Returns:An IRI, a list or a set of IRIs or None.
set(resource, value)[source]

See set().

Accepts Resource object(s) or IRI(s).

oldman.model.converter module

class oldman.model.converter.DirectMappingModelConverter(client_to_store_mappings)[source]

Bases: oldman.model.converter.ModelConverter

from_client_to_store(client_resource, store_resource)[source]
from_store_to_client(store_resource, client_resource)[source]
class oldman.model.converter.EquivalentModelConverter(client_model, store_model)[source]

Bases: oldman.model.converter.DirectMappingModelConverter

TODO: describe

class oldman.model.converter.ModelConversionManager[source]

Bases: object

TODO: describe and find a better name.

convert_client_to_store_resource(client_resource)[source]
convert_store_to_client_resource(store_resource, client_resource_manager)[source]
convert_store_to_client_resources(store_resources, client_resource_manager)[source]

TODO: describe

register_model_converter(client_model, store_model, data_store, model_converter)[source]
class oldman.model.converter.ModelConverter[source]

Bases: object

TODO: find a better name and explain

from_client_to_store(client_resource, store_resource)[source]
from_store_to_client(store_resource, client_resource)[source]

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.

convert_client_resource(client_resource)[source]

Returns converted store resources.

convert_store_resources(store_resources)[source]

Returns converted client resources.

import_model(store_model, data_store, is_default=False)[source]

Imports a store model. Creates the corresponding client model.

resource_manager[source]
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_graphrdflib.Graph object containing all the schema triples.
  • data_storeDataStore object.
  • attr_extractorOMAttributeExtractor 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:

  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.
  • context_iri_or_payloaddict, 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.
  • context_file_path – TODO: describe.
declare_operation_function(func, class_iri, http_method)[source]

TODO: comment

find_descendant_models(top_ancestor_name_or_iri)[source]

TODO: explain. Includes the top ancestor.

find_models_and_types(type_set)[source]

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

get_model(class_name_or_iri)[source]
has_default_model()[source]
include_reversed_attributes[source]

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

models[source]

TODO: describe.

non_default_models[source]

TODO: describe.

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.

classmethod copy_store_model(resource_manager, store_model)[source]

TODO: describe

create(id=None, hashless_iri=None, collection_iri=None, **kwargs)[source]

Creates a new resource and saves it.

See new() for more details.

declare_method(method, name, ancestor_class_iri)[source]

TODO: describe

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.

methods[source]

dict of Python functions that takes as first argument a Resource object. Keys are the method names.

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

Creates a new Resource object without saving it.

The class_iri attribute is added to the types.

See new() for more 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:
  • managerResourceManager 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_attributesdict of OMAttribute objects. Keys are their names.
  • id_generatorIriGenerator object that generates IRIs from new Resource objects.
  • methodsdict 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.
ancestry_iris[source]

IRIs of the ancestry of the attribute class_iri.

class_iri[source]

IRI of the class IRI the model refers to.

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.
get_operation(http_method)[source]

TODO: describe

get_operation_by_name(name)[source]

TODO: describe

has_reversed_attributes[source]

Is True if one of its attributes is reversed.

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:modelModel object to compare with.
Returns:True if is a sub-class of the other model, False otherwise.
local_context[source]

Context available locally (but not to external consumer). TODO: describe further

methods[source]

Models does not support methods by default.

name[source]

Name attribute.

om_attributes[source]

dict of OMAttribute objects. Keys are their names.

reset_counter()[source]

Resets the counter of the IRI generator.

Please use it only for test purposes.

oldman.model.model.clean_context(context)[source]

Cleans the context.

Context can be an IRI, a list or a dict.

oldman.model.operation module

TODO: explain

class oldman.model.operation.Operation(http_method, excepted_type, returned_type, function, name)[source]

Bases: object

TODO: describe

expected_type[source]
name[source]
returned_type[source]
oldman.model.operation.append_to_hydra_collection(collection_resource, new_resources=None, graph=None, **kwargs)[source]

TODO: improve the mechanism of operation

oldman.model.operation.append_to_hydra_paged_collection(collection, graph=None, new_resources=None, **kwargs)[source]
oldman.model.operation.not_implemented(resource, **kwargs)[source]

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.
  • reversedTrue 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.
declare_is_required()[source]

Makes the property be required. Is irreversible.

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)

domains[source]

Set of class IRIs that are declared as the RDFS domain of the property.

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_selectorValueFormatSelector object.
iri[source]

IRI of RDF property.

is_read_only[source]

True if the property cannot be modified by regular end-users.

is_required[source]

True if the property is required.

is_write_only[source]

True if the property cannot be accessed by regular end-users.

TODO: describe

om_attributes[source]

Set of OMAttribute objects that depends on this property.

ranges[source]

Set of class IRIs that are declared as the RDFS range of the property.

reversed[source]

True if the property is reversed (?o ?p ?s).

supporter_class_iri[source]

IRI of the RDFS class that supports the property.

type[source]

The property can be a owl:DatatypeProperty (“datatype”) or an owl:ObjectProperty (“object”). Sometimes its type is unknown (None).

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.

default_model[source]
find_descendant_models(top_ancestor_name_or_iri)[source]

TODO: explain. Includes the top ancestor.

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_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
has_specific_models()[source]
Returns:True if contains other models than the default one.
model_names[source]

Names of the registered models.

models[source]
non_default_models[source]

Non-default 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.

Module contents