Package RDFClosure :: Module CombinedClosure
[hide private]
[frames] | no frames]

Source Code for Module RDFClosure.CombinedClosure

  1  #!/d/Bin/Python/python.exe 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  """ 
  5  The combined closure: performing I{both} the OWL 2 RL and RDFS closures. 
  6  The two are very close but there are some rules in RDFS that are not in OWL 2 RL (eg, the axiomatic 
  7  triples concerning the container membership properties). Using this closure class the 
  8  OWL 2 RL implementation becomes a full extension of RDFS. 
  9   
 10  @requires: U{RDFLib<http://rdflib.net>}, 2.2.2. and higher 
 11  @license: This software is available for use under the U{W3C Software License<http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231>} 
 12  @organization: U{World Wide Web Consortium<http://www.w3.org>} 
 13  @author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} 
 14   
 15  """ 
 16   
 17  """ 
 18  $Id: CombinedClosure.py,v 1.5 2009/09/21 12:04:45 ivan Exp $ $Date: 2009/09/21 12:04:45 $ 
 19  """ 
 20   
 21  __author__  = 'Ivan Herman' 
 22  __contact__ = 'Ivan Herman, ivan@w3.org' 
 23  __license__ = u'W3C® SOFTWARE NOTICE AND LICENSE, http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231' 
 24   
 25  from rdflib.RDFS                import Resource, Class, Datatype 
 26  from RDFClosure.OWL             import OWLClass, Thing, equivalentClass, DataRange 
 27   
 28  from RDFClosure.RDFSClosure     import RDFS_Semantics 
 29  from RDFClosure.OWLRL                   import OWLRL_Semantics 
 30   
 31  ###################################################################################################### 
 32   
33 -class RDFS_OWLRL_Semantics(RDFS_Semantics, OWLRL_Semantics) :
34 """Common subclass of the RDFS and OWL 2 RL semantic classes. All methods simply call back 35 to the functions in the superclasses. This may lead to some unnecessary duplication of terms 36 and rules, but it it not so bad. Also, the additional identification defined for OWL Full, 37 ie, Resource being the same as Thing and OWL and RDFS classes being identical are added to the 38 triple store. 39 40 Note that this class is also a possible user extension point: subclasses can be created that 41 extend the standard functionality by extending this class. This class I{always} performs RDFS inferences. 42 Subclasses have to set the C{self.rdfs} flag explicitly to the requested value if that is to be controlled. 43 44 @ivar full_binding_triples: additional axiom type triples that are added to the combined semantics; these 'bind' the RDFS and the OWL worlds together 45 @ivar rdfs: whether RDFS inference is to be performed or not. In this class instance the value is I{always} C{True}, subclasses may explicitly change it at initialization time. 46 @type rdfs: boolean 47 """ 48 full_binding_triples = [ 49 (Thing, equivalentClass, Resource), 50 (Class, equivalentClass, OWLClass), 51 (DataRange, equivalentClass, Datatype) 52 ]
53 - def __init__(self, graph, axioms, daxioms, rdfs = True) :
54 """ 55 @param graph: the RDF graph to be extended 56 @type graph: rdflib.Graph 57 @param axioms: whether (non-datatype) axiomatic triples should be added or not 58 @type axioms: Boolean 59 @param daxioms: whether datatype axiomatic triples should be added or not 60 @type daxioms: Boolean 61 @param rdfs: placeholder flag (used in subclassed only, it is always defaulted to True in this class) 62 @type rdfs: boolean 63 """ 64 OWLRL_Semantics.__init__(self, graph, axioms, daxioms, rdfs) 65 RDFS_Semantics.__init__(self, graph, axioms, daxioms, rdfs) 66 self.rdfs = True
67
68 - def add_new_datatype(self, uri, conversion_function, datatype_list, subsumption_dict = None, subsumption_key = None, subsumption_list = None ) :
69 """If an extension wants to add new datatypes, this method should be invoked at initialization time. 70 71 @param uri : URI for the new datatypes, like owl_ns["Rational"] 72 @param 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 73 @param datatype_list : list of datatypes already in use that has to be checked 74 @param subsumption_dict : dictionary of subsumption hierarchies (indexed by the datatype URI-s) 75 @param subsumption_key : key in the dictionary, if None, the uri parameter is used 76 @param subsumption_list : list of subsumptions associated to a subsumption key (ie, all datatypes that are superclasses of the new datatype) 77 """ 78 from DatatypeHandling import AltXSDToPYTHON, use_Alt_lexical_conversions 79 80 if datatype_list : datatype_list.append(uri) 81 82 if subsumption_dict and subsumption_list : 83 if subsumption_key : 84 subsumption_dict[subsumption_key] = subsumption_list 85 else : 86 subsumption_dict[uri] = subsumption_list 87 88 AltXSDToPYTHON[uri] = conversion_function 89 use_Alt_lexical_conversions()
90
91 - def post_process(self) :
92 """Do some post-processing step. This method when all processing is done, but before handling possible 93 errors (ie, the method can add its own error messages). By default, this method is empty, subclasses 94 can add content to it by overriding it. 95 """ 96 OWLRL_Semantics.post_process(self)
97
98 - def rules(self, t, cycle_num) :
99 """ 100 @param t: a triple (in the form of a tuple) 101 @param cycle_num: which cycle are we in, starting with 1. This value is forwarded to all local rules; it is also used 102 locally to collect the bnodes in the graph. 103 """ 104 OWLRL_Semantics.rules(self, t, cycle_num) 105 if self.rdfs: RDFS_Semantics.rules(self, t, cycle_num)
106
107 - def add_axioms(self) :
108 if self.rdfs: RDFS_Semantics.add_axioms(self) 109 OWLRL_Semantics.add_axioms(self)
110
111 - def add_d_axioms(self) :
112 if self.rdfs: RDFS_Semantics.add_d_axioms(self) 113 OWLRL_Semantics.add_d_axioms(self)
114
115 - def one_time_rules(self) :
116 """Adds some extra axioms and calls for the d_axiom part of the OWL Semantics.""" 117 for t in self.full_binding_triples : self.store_triple(t) 118 119 # Note that the RL one time rules include the management of datatype which is a true superset 120 # of the rules in RDFS. It is therefore unnecessary to add those even self.rdfs is True. 121 OWLRL_Semantics.one_time_rules(self)
122