oldman.core.model package¶
Submodules¶
oldman.core.model.ancestry module¶
-
class
oldman.core.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.
-
bottom_up
¶ Ancestry list starting from the child.
-
child
¶ 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
¶ Reverse of the bottom_up attribute.
oldman.core.model.attribute module¶
-
class
oldman.core.model.attribute.
Entry
(saved_value=None)[source]¶ Bases:
object
Mutable.
TODO: describe
-
current_value
¶
-
-
class
oldman.core.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 (seeOMProperty
).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 everyResource
object that depends on a givenModel
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.
- resource –
-
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
¶ 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: 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_read_only
¶ True if the property cannot be modified by regular end-users.
-
is_required
¶ 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
¶ True if the property cannot be accessed by regular end-users.
-
jsonld_type
¶ JSON-LD type (datatype IRI or JSON-LD keyword). May be None.
-
language
¶ Its language if localized.
-
name
¶ Its name as an attribute.
-
om_property
¶ OMProperty
to which it belongs.
-
other_attributes
¶ 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: resource – Resource
object.
-
reversed
¶ True if the object and subject in RDF triples should be reversed.
-
set
(resource, value)[source]¶ Sets the attribute value of a resource.
Parameters: - resource –
Resource
object. - value – Its value for this attribute.
- resource –
-
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.
- resource –
-
value_format
¶ ValueFormat
object that validates the format of values and converts RDF values into regular Python objects.
-
class
oldman.core.model.attribute.
OMAttributeMetadata
(name, property, language, jsonld_type, container, reversed)¶ Bases:
tuple
-
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.core.model.attribute.
ObjectOMAttribute
(metadata, value_format)[source]¶ Bases:
oldman.core.model.attribute.OMAttribute
An
ObjectOMAttribute
object is anOMAttribute
object that depends on an owl:ObjectProperty.
oldman.core.model.manager module¶
-
class
oldman.core.model.manager.
ModelManager
(schema_graph=None, attr_extractor=None)[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 extractOMAttribute
for generating newModel
objects. Defaults to a new instance ofOMAttributeExtractor
.
-
find_models_and_types
(type_set)[source]¶ See
oldman.model.registry.ModelRegistry.find_models_and_types()
.
-
include_reversed_attributes
¶ Is True if at least one of its models use some reversed attributes.
-
models
¶ TODO: describe.
-
non_default_models
¶ TODO: describe.
-
schema_graph
¶
- schema_graph –
oldman.core.model.model module¶
-
class
oldman.core.model.model.
Model
(name, class_iri, ancestry_iris, context, om_attributes, accept_new_blank_nodes, 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 toResource
objects that are instances of its RDFS class.It also creates and retrieves
Resource
objects that are instances of its RDFS class. It manages anIriGenerator
object.Model creation
Model
objects are normally created by aResourceManager
object. Please use theoldman.resource.manager.ResourceManager.create_model()
method for creating newModel
objects.Parameters: - 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. - accept_new_blank_nodes – TODO: describe.
- methods – dict of Python functions that takes as first argument a
Resource
object. Keys are the method names. Defaults to {}. TODO: remove?? - local_context – TODO: describe.
-
accept_new_blank_nodes
¶ TODO: describe. Useful for knowing if a bnode ID of a resource is temporary or maybe not.
-
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
¶ IRIs of the ancestry of the attribute class_iri.
-
class_iri
¶ IRI of the class IRI the model refers to.
-
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.
Official context that will be included in the representation.
-
has_reversed_attributes
¶ 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: model – Model
object to compare with.Returns: True if is a sub-class of the other model, False otherwise.
-
local_context
¶ Context available locally (but not to external consumer). TODO: describe further
-
methods
¶ Models does not support methods by default.
-
name
¶ Name attribute.
-
om_attributes
¶ dict of
OMAttribute
objects. Keys are their names.
oldman.core.model.property module¶
-
class
oldman.core.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 itsOMAttribute
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 theOMAttribute
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
¶ IRI that is the default datatype of the property.
May be None (if not defined or if the property is an owl:ObjectProperty)
-
domains
¶ 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_selector – ValueFormatSelector
object.
-
iri
¶ IRI of RDF property.
-
is_read_only
¶ True if the property cannot be modified by regular end-users.
-
is_required
¶ True if the property is required.
-
is_write_only
¶ True if the property cannot be accessed by regular end-users.
-
link_class_iri
¶ TODO: describe
-
om_attributes
¶ Set of
OMAttribute
objects that depends on this property.
-
ranges
¶ Set of class IRIs that are declared as the RDFS range of the property.
-
reversed
¶ True if the property is reversed (?o ?p ?s).
-
supporter_class_iri
¶ IRI of the RDFS class that supports the property.
-
type
¶ The property can be a owl:DatatypeProperty (“datatype”) or an owl:ObjectProperty (“object”). Sometimes its type is unknown (None).
oldman.core.model.registry module¶
-
class
oldman.core.model.registry.
ModelRegistry
[source]¶ Bases:
object
A
ModelRegistry
object registers theModel
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). Seefind_models_and_types()
for more details.-
default_model
¶
-
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
-
model_names
¶ Names of the registered models.
-
models
¶
-
non_default_models
¶ Non-default models.
-