CombinedClosure

The combined closure: performing both the OWL 2 RL and RDFS closures.

The two are very close but there are some rules in RDFS that are not in OWL 2 RL (eg, the axiomatic triples concerning the container membership properties). Using this closure class the OWL 2 RL implementation becomes a full extension of RDFS.

Requires: RDFLib, 4.0.0 and higher.

License: This software is available for use under the W3C Software License.

Organization: World Wide Web Consortium

Author: Ivan Herman

class owlrl.CombinedClosure.RDFS_OWLRL_Semantics(graph, axioms, daxioms, rdfs=True)[source]

Bases: owlrl.RDFSClosure.RDFS_Semantics, owlrl.OWLRL.OWLRL_Semantics

Common subclass of the RDFS and OWL 2 RL semantic classes. All methods simply call back to the functions in the superclasses. This may lead to some unnecessary duplication of terms and rules, but it it not so bad. Also, the additional identification defined for OWL Full, ie, Resource being the same as Thing and OWL and RDFS classes being identical are added to the triple store.

Note that this class is also a possible user extension point: subclasses can be created that extend the standard functionality by extending this class. This class always} performs RDFS inferences. Subclasses have to set the self.rdfs flag explicitly to the requested value if that is to be controlled.

Parameters:
  • graph (rdflib.Graph) – The RDF graph to be extended.
  • axioms (bool) – Whether (non-datatype) axiomatic triples should be added or not.
  • daxioms (bool) – Whether datatype axiomatic triples should be added or not.
  • rdfs (bool) – Placeholder flag (used in subclassed only, it is always defaulted to True in this class)
Variables:
  • full_binding_triples – Additional axiom type triples that are added to the combined semantics; these ‘bind’ the RDFS and the OWL worlds together.
  • rdfs – (bool) Whether RDFS inference is to be performed or not. In this class instance the value is always True, subclasses may explicitly change it at initialization time.
add_axioms()[source]

Add axioms

add_d_axioms()[source]

This is not really complete, because it just uses the comparison possibilities that RDFLib provides.

add_error(message)

Add an error message

Parameters:message (str) – Error message.
static add_new_datatype(uri, conversion_function, datatype_list, subsumption_dict=None, subsumption_key=None, subsumption_list=None)[source]

If an extension wants to add new datatypes, this method should be invoked at initialization time.

Parameters:
  • uri – URI for the new datatypes, like owl_ns[“Rational”].
  • conversion_function – A function converting the lexical representation of the datatype to a Python value, possibly raising an exception in case of unsuitable lexical form.
  • datatype_list (list) – List of datatypes already in use that has to be checked.
  • subsumption_dict (dict) – Dictionary of subsumption hierarchies (indexed by the datatype URI-s).
  • subsumption_key (str) – Key in the dictionary, if None, the uri parameter is used.
  • subsumption_list (list) – List of subsumptions associated to a subsumption key (ie, all datatypes that are superclasses of the new datatype).
closure()

Generate the closure the graph. This is the real ‘core’.

The processing rules store new triples via the separate method Core.store_triple() which stores them in the added_triples array. If that array is empty at the end of a cycle, it means that the whole process can be stopped.

If required, the relevant axiomatic triples are added to the graph before processing in cycles. Similarly the exchange of literals against bnodes is also done in this step (and restored after all cycles are over).

empty_stored_triples()

Empty the internal store for triples.

flush_stored_triples()

Send the stored triples to the graph, and empty the container.

full_binding_triples = [(rdflib.term.URIRef('http://www.w3.org/2002/07/owl#Thing'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#equivalentClass'), rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Resource')), (rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Class'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#equivalentClass'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#Class')), (rdflib.term.URIRef('http://www.w3.org/2002/07/owl#DataRange'), rdflib.term.URIRef('http://www.w3.org/2002/07/owl#equivalentClass'), rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Datatype'))]
one_time_rules()[source]

Adds some extra axioms and calls for the d_axiom part of the OWL Semantics.

post_process()[source]

Do some post-processing step. This method when all processing is done, but before handling possible errors (I.e., the method can add its own error messages). By default, this method is empty, subclasses can add content to it by overriding it.

pre_process()

Do some pre-processing step. This method before anything else in the closure. By default, this method is empty, subclasses can add content to it by overriding it.

restriction_typing_check(v, t)

Helping method to check whether a type statement is in line with a possible restriction. This method is invoked by rule “cls-avf” before setting a type on an allValuesFrom restriction.

The method is a placeholder at this level. It is typically implemented by subclasses for extra checks, e.g., for datatype facet checks.

Parameters:
  • v – The resource that is to be ‘typed’.
  • t – The targeted type (ie, Class).
Returns:

Boolean.

Return type:

bool

rules(t, cycle_num)[source]
Parameters:
  • t (tuple) – A triple (in the form of a tuple).
  • cycle_num (int) – Which cycle are we in, starting with 1. This value is forwarded to all local rules; it is also used locally to collect the bnodes in the graph.
store_triple(t)

In contrast to its name, this does not yet add anything to the graph itself, it just stores the tuple in an internal set (Core.added_triples). (It is important for this to be a set: some of the rules in the various closures may generate the same tuples several times.) Before adding the tuple to the set, the method checks whether the tuple is in the final graph already (if yes, it is not added to the set).

The set itself is emptied at the start of every processing cycle; the triples are then effectively added to the graph at the end of such a cycle. If the set is actually empty at that point, this means that the cycle has not added any new triple, and the full processing can stop.

Parameters:t (tuple (s,p,o)) – The triple to be added to the graph, unless it is already there