Package RDFClosure :: Module Closure :: Class Core
[hide private]
[frames] | no frames]

Class Core

source code

Known Subclasses:

Core of the semantics management, dealing with the RDFS and other Semantic triples. The only reason to have it in a separate class is for an easier maintainability.

This is a common superclass only. In the present module, it is subclassed by a RDFS Closure class and a OWL RL Closure classes. There are some methods that are implemented in the subclasses only, ie, this class cannot be used by itself!

Instance Methods [hide private]
 
__init__(self, graph, axioms, daxioms, rdfs=False) source code
 
add_error(self, message)
Add an error message
source code
 
pre_process(self)
Do some pre-processing step.
source code
 
post_process(self)
Do some post-processing step.
source code
 
rules(self, t, cycle_num)
The core processing cycles through every tuple in the graph and dispatches it to the various methods implementing a specific group of rules.
source code
 
add_axioms(self)
Add axioms.
source code
 
add_d_axioms(self)
Add d axioms.
source code
 
one_time_rules(self)
This is only a placeholder; subclasses should fill this with real content.
source code
 
get_literal_value(self, node)
Return the literal value corresponding to a Literal node.
source code
 
empty_stored_triples(self)
Empty the internal store for triples
source code
 
flush_stored_triples(self)
Send the stored triples to the graph, and empty the container
source code
 
store_triple(self, 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.
source code
 
closure(self)
Generate the closure the graph.
source code
Instance Variables [hide private]
  IMaxNum
maximal index of rdf:_i occurrence in the graph
set of triples added_triples
triples added to the graph, conceptually, during one processing cycle
boolean axioms
whether axioms should be added or not
boolean daxioms
whether datatype axioms should be added or not
array of strings error_messages
error messages (typically inconsistency messages in OWL RL) found during processing.
rdflib.Graph graph
the real graph
LiteralProxies literal_proxies
Literal Proxies with BNodes for the graph
boolean rdfs
whether RDFS inference is also done (used in subclassed only)
Method Details [hide private]

__init__(self, graph, axioms, daxioms, rdfs=False)
(Constructor)

source code 
Parameters:
  • graph (rdflib.Graph) - the RDF graph to be extended
  • axioms (boolean) - whether axioms should be added or not
  • daxioms (boolean) - whether datatype axioms should be added or not
  • rdfs (boolean) - whether RDFS inference is also done (used in subclassed only)

add_error(self, message)

source code 

Add an error message

Parameters:
  • message (string) - error message

pre_process(self)

source code 

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.

post_process(self)

source code 

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

rules(self, t, cycle_num)

source code 

The core processing cycles through every tuple in the graph and dispatches it to the various methods implementing a specific group of rules. By default, this method raises an exception; indeed, subclasses must add content to by overriding it.

Parameters:
  • t (tuple) - one triple on which to apply the rules
  • cycle_num - 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.

add_axioms(self)

source code 

Add axioms. This is only a placeholder and raises an exception by default; subclasses must fill this with real content

add_d_axioms(self)

source code 

Add d axioms. This is only a placeholder and raises an exception by default; subclasses must fill this with real content

one_time_rules(self)

source code 

This is only a placeholder; subclasses should fill this with real content. By default, it is just an empty call. This set of rules is invoked only once and not in a cycle.

get_literal_value(self, node)

source code 

Return the literal value corresponding to a Literal node. Used in error messages.

Parameters:
  • node - literal node
Returns:
the literal value itself

store_triple(self, t)

source code 

In contrast to its name, this does not yet add anything to the graph itself, it just stores the tuple in an internal set. (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 (a 3-element tuple of (s,p,o)) - the triple to be added to the graph, unless it is already there

closure(self)

source code 

Generate the closure the graph. This is the real 'core'.

The processing rules store new triples via the separate method which stores them in the added_triples array. If that array is emtpy 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).


Instance Variable Details [hide private]

error_messages

error messages (typically inconsistency messages in OWL RL) found during processing. These are added to the final graph at the very end as separate BNodes with error messages
Type:
array of strings