def transform(self, graph): """ Transforms a universal restriction on a 'pure' nominal range into a conjunction of value restriction (using set theory and demorgan's laws) """ Individual.factoryGraph = graph for restriction, intermediateCl, \ nominal, prop, partition in graph.query( self.NOMINAL_QUERY, initNs={'owl': OWL_NS, 'rdfs': RDFS}): exceptions = EnumeratedClass() partition = Collection(graph, partition) nominalCollection = Collection(graph, nominal) for i in partition: if i not in nominalCollection: exceptions._rdfList.append(i) # exceptions += i exists = Class(complementOf=(Property(prop) | some | exceptions)) for s, p, o in graph.triples((None, None, restriction)): graph.add((s, p, exists.identifier)) Individual(restriction).delete() #purge nominalization placeholder iClass = BooleanClass(intermediateCl) iClass.clear() iClass.delete()
def transform(self, graph): """ Transforms a 'pure' nominal range into a disjunction of value restrictions """ Individual.factoryGraph = graph for restriction, intermediateCl, nominal, prop in graph.query( self.NOMINAL_QUERY, initNs={'owl': OWL_NS}): nominalCollection = Collection(graph, nominal) # purge restriction restr = Class(restriction) parentSets = [i for i in restr.subClassOf] restr.clearOutDegree() newConjunct = BooleanClass(restriction, OWL_NS.unionOf, [Property(prop) | value | val for val in nominalCollection], graph) newConjunct.subClassOf = parentSets # purge nominalization placeholder iClass = BooleanClass(intermediateCl) iClass.clear() iClass.delete()
def transform(self, graph): """ Transforms a universal restriction on a 'pure' nominal range into a conjunction of value restriction (using set theory and demorgan's laws) """ Individual.factoryGraph = graph for restriction, intermediateCl, nominal, prop, partition in graph.query( self.NOMINAL_QUERY, initNs={ u'owl': OWL_NS, u'rdfs': str(RDFS) }): exceptions = EnumeratedClass() partition = Collection(graph, partition) nominalCollection = Collection(graph, nominal) for i in partition: if i not in nominalCollection: exceptions._rdfList.append(i) #exceptions+=i exists = Class(complementOf=(Property(prop) | some | exceptions)) for s, p, o in graph.triples((None, None, restriction)): graph.add((s, p, exists.identifier)) Individual(restriction).delete() #purge nominalization placeholder iClass = BooleanClass(intermediateCl) iClass.clear() iClass.delete()
def transform(self, graph): """ Transforms a 'pure' nominal range into a disjunction of value restrictions """ Individual.factoryGraph = graph for restriction, intermediateCl, nominal, prop in graph.query( self.NOMINAL_QUERY, initNs={u'owl': OWL_NS}): nominalCollection = Collection(graph, nominal) #purge restriction restr = Class(restriction) parentSets = [i for i in restr.subClassOf] restr.clearOutDegree() newConjunct = BooleanClass( restriction, OWL_NS.unionOf, [Property(prop) | value | val for val in nominalCollection], graph) newConjunct.subClassOf = parentSets #purge nominalization placeholder iClass = BooleanClass(intermediateCl) iClass.clear() iClass.delete()
def transform(self, graph): """ Uses DeMorgan's laws to reduce negated disjunctions to a conjunction of negated formulae """ Individual.factoryGraph = graph for disjunctId in graph.subjects(predicate=OWL_NS.unionOf): if (None, OWL_NS.complementOf, disjunctId) in graph and \ isinstance(disjunctId, BNode): # not ( A1 or A2 or .. or An ) # = # ( not A1 and not A2 and .. and not An ) disjunct = BooleanClass(disjunctId, operator=OWL_NS.unionOf) items = list(disjunct) newConjunct = BooleanClass( members=[~Class(item) for item in items]) for negation in graph.subjects(predicate=OWL_NS.complementOf, object=disjunctId): Class(negation).replace(newConjunct) if not isinstance(negation, BNode): newConjunct.identifier = negation disjunct.clear() disjunct.delete() elif ((disjunctId, OWL_NS.unionOf, None) in graph) and not \ [item for item in BooleanClass(disjunctId, operator=OWL_NS.unionOf) if not Class(item).complementOf]: #( not A1 or not A2 or .. or not An ) # = #not ( A1 and A2 and .. and An ) disjunct = BooleanClass(disjunctId, operator=OWL_NS.unionOf) items = [Class(item).complementOf for item in disjunct] for negation in disjunct: Class(negation).delete() negatedConjunct = ~ BooleanClass(members=items) disjunct.clear() disjunct.replace(negatedConjunct)
def transform(self, graph): """ Uses demorgan's laws to reduce negated disjunctions to a conjunction of negated formulae """ Individual.factoryGraph = graph for disjunctId in graph.subjects(predicate=OWL_NS.unionOf): if (None, OWL_NS.complementOf, disjunctId) in graph and \ isinstance(disjunctId, BNode): #not ( A1 or A2 or .. or An ) # = # ( not A1 and not A2 and .. and not An ) disjunct = BooleanClass(disjunctId, operator=OWL_NS.unionOf) items = list(disjunct) newConjunct = BooleanClass( members=[~Class(item) for item in items]) for negation in graph.subjects(predicate=OWL_NS.complementOf, object=disjunctId): Class(negation).replace(newConjunct) if not isinstance(negation, BNode): newConjunct.identifier = negation disjunct.clear() disjunct.delete() elif ((disjunctId, OWL_NS.unionOf, None) in graph) and not \ [item for item in BooleanClass(disjunctId, operator=OWL_NS.unionOf) if not Class(item).complementOf]: #( not A1 or not A2 or .. or not An ) # = #not ( A1 and A2 and .. and An ) disjunct = BooleanClass(disjunctId, operator=OWL_NS.unionOf) items = [Class(item).complementOf for item in disjunct] for negation in disjunct: Class(negation).delete() negatedConjunct = ~BooleanClass(members=items) disjunct.clear() disjunct.replace(negatedConjunct)