def checkmatchforOWLtermandnodename(self, OWL_term_1, OWL_term_2): # it should not be a complement of a class; i.e. the raw term should start with < if (OWL_term_1 is None) or (OWL_term_2 is None): return False if str(type(OWL_term_1)) == '<class \'list\'>': for t1 in OWL_term_1: if str(type(OWL_term_2)) == '<class \'list\'>': for t2 in OWL_term_2: if (t1[0] == '<') and (t2[0] == '<'): if t1 == t2: return True else: if (t1[0] == '<') and (t2[0] == '<'): if t1 == t2: return True if (OWL_term_1[0] == '<') and (OWL_term_2[0] == '<'): if OWL_term_1 == OWL_term_2: return True top_and_bottom_entities = [] top_and_bottom_entities.extend( Special.return_group(Special.AllTopEntities)) top_and_bottom_entities.extend( Special.return_group(Special.AllBottomEntities)) if (OWL_term_1 in top_and_bottom_entities) and (OWL_term_1 == OWL_term_2): return True return False
def __call__(self, source, edge, target): if edge.type() is Item.InputEdge: if target.type() in { Item.DomainRestrictionNode, Item.RangeRestrictionNode }: # OWL 2 QL admits only atomic concepts for role qualified restriction. if source.identity() is Identity.Concept: if source.type() is not Item.ConceptNode: raise ProfileError( 'OWL 2 QL admits only an atomic concept as filler for a qualified {}' .format(target.shortName)) # Given the fact that we are connecting an atomic concept in input to this # restriction node, we need to see if the node is currently being used # as source for a concept expression inclusion, and if so, deny the connection # because OWL 2 QL admits concept inclusion sourcing only from unqualified role # restrictions (we need to skip TOP though, since it won't be qualified then). if (Special.valueOf(source.text()) is not Special.Top) and \ (Special.valueOf(source.text()) is not Special.TopConcept) and \ (Special.valueOf(source.text()) is not Special.TopRole) and\ (Special.valueOf(source.text()) is not Special.TopAttribute): # We found an outgoing inclusion edge and our restriction filler is not TOP. if target.outgoingNodes(filter_on_edges=lambda x: x. type() is Item.InclusionEdge): raise ProfileError( 'Inclusion with a qualified {} as source is forbidden in OWL 2 QL' .format(target.shortName)) # Similarly we block the input in case of equivalence edges attached to the restriction node. if target.adjacentNodes( filter_on_edges=lambda x: x.type( ) is Item.EquivalenceEdge): raise ProfileError( 'Equivalence in presence of qualified {} is forbidden in OWL 2 QL' .format(target.shortName))
def isRestrictionQualified(self): """ Returna True if this node expresses a qualified restriction (exists R.C), False otherwise. :rtype: bool """ f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.identity() in {Identity.Concept, Identity.Role} f3 = lambda x: x.identity( ) in {Identity.Attribute, Identity.ValueDomain} f4 = lambda x: x.identity() is Identity.Concept if self.restriction() in { Restriction.Cardinality, Restriction.Exists, Restriction.Forall }: # CHECK FOR ROLE QUALIFIED RESTRICTION collection = self.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2) if len(collection) >= 2: node = first(collection, filter_on_item=f4) if (node and Special.valueOf(node.text()) is not Special.Top) and \ (node and Special.valueOf(node.text()) is not Special.TopConcept) and \ (node and Special.valueOf(node.text()) is not Special.TopAttribute) and \ (node and Special.valueOf(node.text()) is not Special.TopRole): return True # CHECK FOR ATTRIBUTE QUALIFIED RESTRICTION return len( self.incomingNodes(filter_on_edges=f1, filter_on_nodes=f3)) >= 2 return False
def __call__(self, source, edge, target): if edge.type() is Item.InclusionEdge: # We need to provide rules for OWL 2 RL concept inclusion. Value-Domain inclusions # are already forbidden by OWL 2 rules, so here we just consider the case where we # are connecting endpoints that either both Neutral, or at least one of the 2 is # identified as a Concept expression. if not {Identity.Role, Identity.Attribute, Identity.Unknown} & {source.identity(), target.identity()}: ############################################# # EVALUATE INCLUSION SOURCE ################################# # TOP concept cannot be source of concept inclusion in OWL 2 RL. if source.type() is Item.ConceptNode: if Special.forValue(source.text()) is Special.Top: raise ProfileError('Inclusion with a TOP concept as source is forbidden in OWL 2 RL') # Complement nodes cannot be source of concept inclusion in OWL 2 RL. elif source.type() is Item.ComplementNode: raise ProfileError('Inclusion with a concept complement as source is forbidden in OWL 2 RL') # OWL 2 RL admits only existential restriction as source for inclusion. elif source.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}: if source.restriction() is not Restriction.Exists: r = source.restriction() raise ProfileError('Inclusion with a {} {} as source is forbidden in OWL 2 RL'.format(r.shortName, source.shortName)) ############################################# # EVALUATE INCLUSION TARGET ################################# # TOP concept cannot be target of concept inclusion in OWL 2 RL. if target.type() is Item.ConceptNode: if Special.forValue(target.text()) is Special.Top: raise ProfileError('Inclusion with a TOP concept as target is forbidden in OWL 2 RL') # Enumeration nodes cannot be target of concept inclusion in OWL 2 RL. elif target.type() is Item.EnumerationNode: raise ProfileError('Inclusion with an enumeration of individuals as target is forbidden in OWL 2 RL') # Union of concept expressions cannot be target of concept inclusion in OWL 2 RL. elif target.type() is Item.EnumerationNode: raise ProfileError('Inclusion with a union of concept expressions as target is forbidden in OWL 2 RL') # Existential domain/range restriction and cardinality check. elif target.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}: if target.restriction() is Restriction.Exists: # We need to check for the restriction to have a an Enumeration as filler. f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.EnumerationNode if not target.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2): raise ProfileError('Existential {} must specify an Enumeration as filler when acting as ' 'target for a concept expression inclusion in OWL 2 RL'.format(target.shortName)) elif target.restriction() is Restriction.Cardinality: if target.cardinality('max') not in (0, 1): raise ProfileError('Cardinality {} must specify a max cardinality of 0 or 1 when acting as ' 'target for a concept expression inclusion in OWL 2 RL'.format(target.shortName))
def special(self): """ Returns the special type of this node. :rtype: Special """ # TODO implementa nuova versione passando da metodo IRI.isTopBottomEntity (isOWlThing? etc etc...) return Special.valueOf(self.text())
def __call__(self, source, edge, target): if edge.type() is Item.InclusionEdge: # Similarily as for the Inclusion edge, we provide rules for OWL 2 RL concept expressions equivalence. # Because equivalence express a double inclusion we treat each of the endpoints in the same way. if not {Identity.Role, Identity.Attribute, Identity.Unknown} & {source.identity(), target.identity()}: for node in (source, target): # TOP concept cannot be part of concept equivalence in OWL 2 RL. if node.type() is Item.ConceptNode: if Special.forValue(node.text()) is Special.Top: raise ProfileError('Equivalence in presence of a TOP concept is forbidden in OWL 2 RL') # Complement nodes cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.ComplementNode: raise ProfileError('Equivalence in presence of a concept complement is forbidden in OWL 2 RL') # Enumeration nodes cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.EnumerationNode: raise ProfileError('Equivalence in presence of an enumeration of individuals is forbidden in OWL 2 RL') # Union of concept expressions cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.EnumerationNode: raise ProfileError('Equivalence in presence of a union of concept expressions is forbidden in OWL 2 RL') # Domain/range restriction cannot be part of concept equivalence in OWL 2 RL. elif node.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}: f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.EnumerationNode if not node.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2): raise ProfileError('Existential {} must specify an Enumeration as filler when involved ' 'in an equivalence between concept expressions in OWL 2 RL'.format(target.shortName))
def __call__(self, source, edge, target): if edge.type() is Item.InclusionEdge: # Similarily as for the Inclusion edge, we provide rules for OWL 2 RL concept expressions equivalence. # Because equivalence express a double inclusion we treat each of the endpoints in the same way. if not {Identity.Role, Identity.Attribute, Identity.Unknown} & { source.identity(), target.identity() }: for node in (source, target): # TOP concept cannot be part of concept equivalence in OWL 2 RL. if node.type() is Item.ConceptNode: if (Special.valueOf(node.text()) is Special.Top) or \ (Special.valueOf(node.text()) is Special.TopConcept) or \ (Special.valueOf(node.text()) is Special.TopAttribute) or \ (Special.valueOf(node.text()) is Special.TopRole): raise ProfileError( 'Equivalence in presence of a TOP concept is forbidden in OWL 2 RL' ) # Complement nodes cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.ComplementNode: raise ProfileError( 'Equivalence in presence of a concept complement is forbidden in OWL 2 RL' ) # Enumeration nodes cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.EnumerationNode: raise ProfileError( 'Equivalence in presence of an enumeration of individuals is forbidden in OWL 2 RL' ) # Union of concept expressions cannot be part of concept equivalence in OWL 2 RL. elif node.type() is Item.EnumerationNode: raise ProfileError( 'Equivalence in presence of a union of concept expressions is forbidden in OWL 2 RL' ) # Domain/range restriction cannot be part of concept equivalence in OWL 2 RL. elif node.type() in { Item.DomainRestrictionNode, Item.RangeRestrictionNode }: f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.EnumerationNode if not node.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2): raise ProfileError( 'Existential {} must specify an Enumeration as filler when involved ' 'in an equivalence between concept expressions in OWL 2 RL' .format(target.shortName))
def isRestrictionQualified(self): """ Returna True if this node expresses a qualified restriction (exists R.C), False otherwise. :rtype: bool """ f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.identity() in {Identity.Concept, Identity.Role} f3 = lambda x: x.identity() in {Identity.Attribute, Identity.ValueDomain} f4 = lambda x: x.identity() is Identity.Concept if self.restriction() in {Restriction.Cardinality, Restriction.Exists, Restriction.Forall}: # CHECK FOR ROLE QUALIFIED RESTRICTION collection = self.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2) if len(collection) >= 2: node = first(collection, filter_on_item=f4) if node and Special.forValue(node.text()) is not Special.Top: return True # CHECK FOR ATTRIBUTE QUALIFIED RESTRICTION return len(self.incomingNodes(filter_on_edges=f1, filter_on_nodes=f3)) >= 2 return False
def __call__(self, source, edge, target): if edge.type() is Item.InputEdge: if target.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}: # OWL 2 QL admits only atomic concepts for role qualified restriction. if source.identity() is Identity.Concept: if source.type() is not Item.ConceptNode: raise ProfileError('OWL 2 QL admits only an atomic concept as filler for a qualified {}'.format(target.shortName)) # Given the fact that we are connecting an atomic concept in input to this # restriction node, we need to see if the node is currently being used # as source for a concept expression inclusion, and if so, deny the connection # because OWL 2 QL admits concept inclusion sourcing only from unqualified role # restrictions (we need to skip TOP though, since it won't be qualified then). if Special.forValue(source.text()) is not Special.Top: # We found an outgoing inclusion edge and our restriction filler is not TOP. if target.outgoingNodes(filter_on_edges=lambda x: x.type() is Item.InclusionEdge): raise ProfileError('Inclusion with a qualified {} as source is forbidden in OWL 2 QL'.format(target.shortName)) # Similarly we block the input in case of equivalence edges attached to the restriction node. if target.adjacentNodes(filter_on_edges=lambda x: x.type() is Item.EquivalenceEdge): raise ProfileError('Equivalence in presence of qualified {} is forbidden in OWL 2 QL'.format(target.shortName))
def special(self): """ Returns the special type of this node. :rtype: Special """ return Special.valueOf(self.text())
def run(self, path): """ Perform PDF document generation. :type path: str """ printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution) printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat) printer.setOutputFileName(path) printer.setOrientation(QtPrintSupport.QPrinter.Landscape) printer.setPrinterName(self.project.name) painter = QtGui.QPainter() # DIAGRAM SELECTION if self.diagrams is None: dialog = DiagramSelectionDialog(self.session) if not dialog.exec_(): return self.diagrams = dialog.selectedDiagrams() # DIAGRAM PAGE SIZE SELECTION if self.pageSize is None: dialog = PageSetupDialog(printer, self.session) if not dialog.exec_(): return else: printer.setPageSize(self.pageSize) ############################################################## # DIAGRAMS ############################################################## for n, diagram in enumerate(natsorted(self.diagrams, key=lambda diagram: diagram.name)): shape = diagram.visibleRect(margin=400) if shape: if n > 0: printer.newPage() if painter.isActive() or painter.begin(printer): # TURN CACHING OFF for item in diagram.items(): if item.isNode() or item.isEdge(): item.setCacheMode(AbstractItem.NoCache) # RENDER THE DIAGRAM diagram.render(painter, source=shape) # RENDER DIAGRAM NAME title = QtGui.QTextDocument() title.setDefaultFont(Font(pixelSize=140)) title.setHtml('{0}<hr width=100%/>'.format(diagram.name)) title.setTextWidth(printer.pageRect().width()) title.drawContents(painter) # TURN CACHING ON for item in diagram.items(): if item.isNode() or item.isEdge(): item.setCacheMode(AbstractItem.DeviceCoordinateCache) ############################################################## # IRI TABLE ############################################################## # RESET PAGE SIZE AND ORIENTATION FOR PREDICATE TABLES printer.setPageSize(QtPrintSupport.QPrinter.A4) printer.setOrientation(QtPrintSupport.QPrinter.Landscape) printer.setPageMargins(12.5, 12.5, 12.5, 12.5, QtPrintSupport.QPrinter.Millimeter) prefixRows = [] for iri in sorted(self.project.IRI_prefixes_nodes_dict.keys()): for prefix in self.project.IRI_prefixes_nodes_dict[iri][0]: prefixRows.append(dedent(''' <tr> <td width=25%>{0}</td> <td width=75%>{1}</td> </tr> '''.format(prefix, iri))) sections = [prefixRows[i:i+self.rowsPerPage] for i in range(0, len(prefixRows), self.rowsPerPage)] for section in sections: if len(section) > 0: if len(self.diagrams) > 0: printer.newPage() doc = QtGui.QTextDocument() htmlTable = ''' <table width=100% border=5 cellspacing=0 cellpadding=60> <thead> <tr> <th bgcolor=#c8c8c8>PREFIX</th> <th bgcolor=#c8c8c8>IRI</th> </tr> </thead> <tbody>''' htmlTable += '\n'.join(section) htmlTable += '</tbody>' htmlTable += '</table>' doc.setDefaultFont(Font(pixelSize=180)) doc.setHtml(htmlTable) doc.setPageSize(QtCore.QSizeF(printer.pageRect().size())) doc.drawContents(painter) ############################################################## # ROLES AND ATTRIBUTES TABLE ############################################################## predicateRows = [] predicates = set() for item in {Item.RoleNode, Item.AttributeNode}: for predicate in self.project.predicates(item=item): if not predicate.text() in Special.return_group(Special.AllTopEntities) \ or predicate.text() in Special.return_group(Special.AllBottomEntities): predicates.add(predicate.text().replace('\n', '')) for predicate in sorted(predicates): meta = self.project.meta(Item.RoleNode, predicate) or \ self.project.meta(Item.AttributeNode, predicate) or \ {} attributes = [ meta.get(K_FUNCTIONAL, False), meta.get(K_INVERSE_FUNCTIONAL, False), meta.get(K_REFLEXIVE, False), meta.get(K_IRREFLEXIVE, False), meta.get(K_SYMMETRIC, False), meta.get(K_ASYMMETRIC, False), meta.get(K_TRANSITIVE, False), ] predicateRows.append(''' <tr> <td width=30%>{0}</td> <td width=10%><center>{1}</center></td> <td width=10%><center>{2}</center></td> <td width=10%><center>{3}</center></td> <td width=10%><center>{4}</center></td> <td width=10%><center>{5}</center></td> <td width=10%><center>{6}</center></td> <td width=10%><center>{7}</center></td> </tr> '''.format(predicate, *map(lambda x: u'\u2713' if x else '', attributes))) sections = [predicateRows[i:i+self.rowsPerPage] for i in range(0, len(predicateRows), self.rowsPerPage)] for section in sections: if len(section) > 0: if len(self.diagrams) > 0: printer.newPage() doc = QtGui.QTextDocument() htmlTable = ''' <table width=100% border=5 cellspacing=0 cellpadding=60> <thead> <tr> <th bgcolor=#c8c8c8>ENTITY</th> <th bgcolor=#c8c8c8>FUNCT</th> <th bgcolor=#c8c8c8>INVERSE FUNCT</th> <th bgcolor=#c8c8c8>TRANS</th> <th bgcolor=#c8c8c8>REFL</th> <th bgcolor=#c8c8c8>IRREFL</th> <th bgcolor=#c8c8c8>SYMM</th> <th bgcolor=#c8c8c8>ASYMM</th> </tr> </thead> <tbody>''' htmlTable += '\n'.join(section) htmlTable += '</tbody>' htmlTable += '</table>' doc.setDefaultFont(Font(pixelSize=180)) doc.setHtml(htmlTable) doc.setPageSize(QtCore.QSizeF(printer.pageRect().size())) doc.drawContents(painter) # COMPLETE THE EXPORT if painter.isActive(): painter.end() # OPEN THE DOCUMENT if self.open: openPath(printer.outputFileName())
def FillTableWithMetaDataInfoForRolesAndAttributes(self): self.table_2.setRowCount(1) self.table_2.setColumnCount(8) header_entity = QtWidgets.QTableWidgetItem() header_entity.setText('ENTITY') header_entity.setFont(Font('Roboto', 15, bold=True)) header_entity.setTextAlignment(QtCore.Qt.AlignCenter) header_entity.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_entity.setForeground(QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_entity.setFlags(QtCore.Qt.NoItemFlags) header_functional = QtWidgets.QTableWidgetItem() header_functional.setText('FUNCT') header_functional.setFont(Font('Roboto', 15, bold=True)) header_functional.setTextAlignment(QtCore.Qt.AlignCenter) header_functional.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_functional.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_functional.setFlags(QtCore.Qt.NoItemFlags) header_inversefunctional = QtWidgets.QTableWidgetItem() header_inversefunctional.setText('INV\nFUNCT') header_inversefunctional.setFont(Font('Roboto', 15, bold=True)) header_inversefunctional.setTextAlignment(QtCore.Qt.AlignCenter) header_inversefunctional.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_inversefunctional.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_inversefunctional.setFlags(QtCore.Qt.NoItemFlags) header_transitive = QtWidgets.QTableWidgetItem() header_transitive.setText('TRANS') header_transitive.setFont(Font('Roboto', 15, bold=True)) header_transitive.setTextAlignment(QtCore.Qt.AlignCenter) header_transitive.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_transitive.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_transitive.setFlags(QtCore.Qt.NoItemFlags) header_reflexive = QtWidgets.QTableWidgetItem() header_reflexive.setText('REFL') header_reflexive.setFont(Font('Roboto', 15, bold=True)) header_reflexive.setTextAlignment(QtCore.Qt.AlignCenter) header_reflexive.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_reflexive.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_reflexive.setFlags(QtCore.Qt.NoItemFlags) header_irreflexive = QtWidgets.QTableWidgetItem() header_irreflexive.setText('IRREFL') header_irreflexive.setFont(Font('Roboto', 15, bold=True)) header_irreflexive.setTextAlignment(QtCore.Qt.AlignCenter) header_irreflexive.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_irreflexive.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_irreflexive.setFlags(QtCore.Qt.NoItemFlags) header_symmetric = QtWidgets.QTableWidgetItem() header_symmetric.setText('SYMM') header_symmetric.setFont(Font('Roboto', 15, bold=True)) header_symmetric.setTextAlignment(QtCore.Qt.AlignCenter) header_symmetric.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_symmetric.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_symmetric.setFlags(QtCore.Qt.NoItemFlags) header_asymmetric = QtWidgets.QTableWidgetItem() header_asymmetric.setText('ASYMM') header_asymmetric.setFont(Font('Roboto', 15, bold=True)) header_asymmetric.setTextAlignment(QtCore.Qt.AlignCenter) header_asymmetric.setBackground( QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))) header_asymmetric.setForeground( QtGui.QBrush(QtGui.QColor(90, 80, 80, 200))) header_asymmetric.setFlags(QtCore.Qt.NoItemFlags) self.table_2.setItem(self.table_2.rowCount() - 1, 0, header_entity) self.table_2.setItem(self.table_2.rowCount() - 1, 1, header_functional) self.table_2.setItem(self.table_2.rowCount() - 1, 2, header_inversefunctional) self.table_2.setItem(self.table_2.rowCount() - 1, 3, header_reflexive) self.table_2.setItem(self.table_2.rowCount() - 1, 4, header_irreflexive) self.table_2.setItem(self.table_2.rowCount() - 1, 5, header_symmetric) self.table_2.setItem(self.table_2.rowCount() - 1, 6, header_asymmetric) self.table_2.setItem(self.table_2.rowCount() - 1, 7, header_transitive) self.table_2.setRowCount(self.table_2.rowCount() + 1) wanted_attributes = [ 'functional', 'inverseFunctional', 'reflexive', 'irreflexive', 'symmetric', 'asymmetric', 'transitive' ] attribute_predicates_filtered = set() for attribute_predicate in self.project.predicates( item=Item.AttributeNode): if (attribute_predicate.text() in Special.return_group( Special.AllTopEntities)) or ( attribute_predicate.text() in Special.return_group( Special.AllBottomEntities)): continue else: attribute_predicates_filtered.add(attribute_predicate.text()) #print('len(attribute_predicates_filtered)',len(attribute_predicates_filtered)) for attribute_predicate_txt in sorted(attribute_predicates_filtered): meta_data = self.project.meta(Item.AttributeNode, attribute_predicate_txt) #print('meta_data',meta_data) attributes = [] if len(meta_data) > 0: for k in wanted_attributes: if k in meta_data: value = meta_data[k] else: value = False attributes.append(value) else: attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) #print(attribute_predicate_txt, '-', attributes) attribute_predicate_plus_attributes = [] attribute_predicate_plus_attributes.append(attribute_predicate_txt) attribute_predicate_plus_attributes.extend(attributes) self.append_row_and_column_to_table_2( attribute_predicate_plus_attributes, entity='attribute') role_predicates_filtered = set() for role_predicate in self.project.predicates(item=Item.RoleNode): if (role_predicate.text() in Special.return_group( Special.AllTopEntities)) or ( role_predicate.text() in Special.return_group( Special.AllBottomEntities)): continue else: role_predicates_filtered.add(role_predicate.text()) #print('len(role_predicates_filtered)', len(role_predicates_filtered)) for role_predicate_txt in sorted(role_predicates_filtered): meta_data = self.project.meta(Item.RoleNode, role_predicate_txt) attributes = [] if len(meta_data) > 0: for k in wanted_attributes: value = meta_data[k] attributes.append(value) else: attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) attributes.append(False) #print(role_predicate_txt,'-',attributes) role_predicate_plus_attributes = [] role_predicate_plus_attributes.append(role_predicate_txt) role_predicate_plus_attributes.extend(attributes) self.append_row_and_column_to_table_2( role_predicate_plus_attributes) self.table_2.setRowCount(self.table_2.rowCount() - 1)
def __call__(self, node): if node.type() in {Item.AttributeNode, Item.RoleNode}: if Special.forValue(node.text()) is not None: raise ProfileError('Usage of {} {} is forbidden in OWL 2 RL'.format(node.text(), node.shortName))
def special(self): """ Returns the special type of this node. :rtype: Special """ return Special.forValue(self.text())
def __call__(self, node): if node.type() in {Item.AttributeNode, Item.RoleNode}: if Special.valueOf(node.text()) is not None: raise ProfileError( 'Usage of {} {} is forbidden in OWL 2 RL'.format( node.text(), node.shortName))
def __call__(self, source, edge, target): if edge.type() is Item.InclusionEdge: # We need to provide rules for OWL 2 RL concept inclusion. Value-Domain inclusions # are already forbidden by OWL 2 rules, so here we just consider the case where we # are connecting endpoints that either both Neutral, or at least one of the 2 is # identified as a Concept expression. if not {Identity.Role, Identity.Attribute, Identity.Unknown} & { source.identity(), target.identity() }: ############################################# # EVALUATE INCLUSION SOURCE ################################# # TOP concept cannot be source of concept inclusion in OWL 2 RL. if source.type() is Item.ConceptNode: if (Special.valueOf(source.text()) is Special.Top) or \ (Special.valueOf(source.text()) is Special.TopConcept) or \ (Special.valueOf(source.text()) is Special.TopAttribute) or \ (Special.valueOf(source.text()) is Special.TopRole): raise ProfileError( 'Inclusion with a TOP concept as source is forbidden in OWL 2 RL' ) # Complement nodes cannot be source of concept inclusion in OWL 2 RL. elif source.type() is Item.ComplementNode: raise ProfileError( 'Inclusion with a concept complement as source is forbidden in OWL 2 RL' ) # OWL 2 RL admits only existential restriction as source for inclusion. elif source.type() in { Item.DomainRestrictionNode, Item.RangeRestrictionNode }: if source.restriction() is not Restriction.Exists: r = source.restriction() raise ProfileError( 'Inclusion with a {} {} as source is forbidden in OWL 2 RL' .format(r.shortName, source.shortName)) ############################################# # EVALUATE INCLUSION TARGET ################################# # TOP concept cannot be target of concept inclusion in OWL 2 RL. if target.type() is Item.ConceptNode: if (Special.valueOf(target.text()) is Special.Top) or \ (Special.valueOf(target.text()) is Special.TopConcept) or \ (Special.valueOf(target.text()) is Special.TopAttribute) or \ (Special.valueOf(target.text()) is Special.TopRole): raise ProfileError( 'Inclusion with a TOP concept as target is forbidden in OWL 2 RL' ) # Enumeration nodes cannot be target of concept inclusion in OWL 2 RL. elif target.type() is Item.EnumerationNode: raise ProfileError( 'Inclusion with an enumeration of individuals as target is forbidden in OWL 2 RL' ) # Union of concept expressions cannot be target of concept inclusion in OWL 2 RL. elif target.type() is Item.EnumerationNode: raise ProfileError( 'Inclusion with a union of concept expressions as target is forbidden in OWL 2 RL' ) # Existential domain/range restriction and cardinality check. elif target.type() in { Item.DomainRestrictionNode, Item.RangeRestrictionNode }: if target.restriction() is Restriction.Exists: # We need to check for the restriction to have a an Enumeration as filler. f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.EnumerationNode if not target.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2): raise ProfileError( 'Existential {} must specify an Enumeration as filler when acting as ' 'target for a concept expression inclusion in OWL 2 RL' .format(target.shortName)) elif target.restriction() is Restriction.Cardinality: if target.cardinality('max') not in (0, 1): raise ProfileError( 'Cardinality {} must specify a max cardinality of 0 or 1 when acting as ' 'target for a concept expression inclusion in OWL 2 RL' .format(target.shortName))