Exemplo n.º 1
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.EquivalenceEdge:
         # Similarily as for the Inclusion edge, here we deny the equivalence in presence
         # of an intersection or a complement node, since it express a double inclusion and
         # we'll violate the constraint imposed by the rule here below.
         if not {Identity.Role, Identity.Attribute, Identity.Unknown} & {
                 source.identity(), target.identity()
         }:
             for node in (source, target):
                 if node.type() is Item.IntersectionNode:
                     raise ProfileError(
                         'Equivalence in presence of concepts intersection is forbidden in OWL 2 QL'
                     )
                 if node.type() is Item.ComplementNode:
                     raise ProfileError(
                         'Equivalence in presence of concept complement is forbidden in OWL 2 QL'
                     )
                 if node.type() in {
                         Item.DomainRestrictionNode,
                         Item.RangeRestrictionNode
                 }:
                     if node.isRestrictionQualified():
                         raise ProfileError(
                             'Equivalence in presence of qualified {} is forbidden in OWL 2 QL'
                             .format(node.shortName))
Exemplo n.º 2
0
 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.ConceptIRINode:
                     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 source.iri and not (source.iri.isOwlThing()
                                        or source.iri.isTopObjectProperty()
                                        or source.iri.isTopDataProperty()):
                     # 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))
Exemplo n.º 3
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.InclusionEdge:
         # We need to prevent inclusions sourcing from Complement nodes and Intersection nodes.
         # Value-Domain inclusions are already forbidden by OWL 2 rules, and Attribute and Role
         # inclusions, with a complement node as enpoint, are already handled in an OWL 2 rule.
         # 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()
         }:
             if source.type() is Item.IntersectionNode:
                 raise ProfileError(
                     'Inclusion with an intersection of concept expressions as source is forbidden in OWL 2 QL'
                 )
             if source.type() is Item.ComplementNode:
                 raise ProfileError(
                     'Inclusion with a concept complement as source is forbidden in OWL 2 QL'
                 )
             if source.type() in {
                     Item.DomainRestrictionNode, Item.RangeRestrictionNode
             }:
                 if source.isRestrictionQualified():
                     raise ProfileError(
                         'Inclusion with a qualified {} as source is forbidden in OWL 2 QL'
                         .format(source.shortName))
Exemplo n.º 4
0
 def __call__(self, node):
     if isinstance(node, OntologyEntityNode) or isinstance(
             node, OntologyEntityResizableNode):
         if node.iri and node.iri.inverseFunctional:
             raise ProfileError(
                 '({}) Functionality of roles is forbidden in OWL 2 QL'.
                 format(str(node.iri)))
Exemplo n.º 5
0
 def __call__(self, node):
     if (('AttributeNode' in str(type(node)))
             or ('RoleNode' in str(type(node)))):
         if node.isFunctional():
             raise ProfileError(
                 'Functionality of roles and attributes is forbidden in OWL 2 QL'
             )
Exemplo n.º 6
0
 def __call__(self, node):
     if node.type() is Item.ValueDomainIRINode:
         if node.iri and not OWL2Datatype.forProfile(OWL2Profiles.OWL2RL):
             raise ProfileError(
                 'Use of datatype {} is forbidden in OWL 2 RL'.format(
                     str(node.iri)))
         '''
Exemplo n.º 7
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.MembershipEdge:
         if source.identity() is Identity.AttributeInstance:
             if target.type() is Item.ComplementNode:
                 raise ProfileError(
                     'Negative attribute assertion is forbidden in OWL 2 QL'
                 )
Exemplo n.º 8
0
 def __call__(self, node):
     if isinstance(node, OntologyEntityNode) or isinstance(
             node, OntologyEntityResizableNode):
         if node.iri and node.iri.transitive:
             raise ProfileError(
                 '({}) Transitivity of roles is forbidden in OWL 2 QL'.
                 format(str(node.iri)))
Exemplo n.º 9
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.InputEdge:
         if target.type() is Item.ComplementNode:
             if source.identity() is Identity.ValueDomain:
                 # We found a complement node with a value-domain expression in input so we must deny it.
                 raise ProfileError(
                     'Complement of a value-domain expression is forbidden in OWL 2 QL'
                 )
Exemplo n.º 10
0
    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))
Exemplo n.º 11
0
 def __call__(self, node):
     if node.type() in {Item.AttributeIRINode, Item.RoleIRINode}:
         if node.iri and (node.iri.isTopObjectProperty()
                          or node.iri.isBottomObjectProperty()
                          or node.iri.isTopDataProperty()
                          or node.iri.isBottomDataProperty()):
             raise ProfileError('Use of {} is forbidden in OWL 2 RL'.format(
                 str(node.iri)))
         '''
Exemplo n.º 12
0
 def __call__(self, node):
     if node.type() in {
             Item.UnionNode, Item.DisjointUnionNode,
             Item.DatatypeRestrictionNode, Item.FacetIRINode,
             Item.EnumerationNode, Item.RoleChainNode
     }:
         raise ProfileError(
             'Usage of {} operator is forbidden in OWL 2 QL'.format(
                 node.shortName))
Exemplo n.º 13
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.InputEdge:
         if target.type() in {Item.DisjointUnionNode, Item.UnionNode}:
             if Identity.ValueDomain in {
                     source.identity(),
                     target.identity()
             }:
                 raise ProfileError(
                     'Union of of value-domain expressions is forbidden in OWL 2 RL'
                 )
Exemplo n.º 14
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.InputEdge:
         if target.type() is Item.IntersectionNode:
             if source.identity() is Identity.ValueDomain:
                 f1 = lambda x: x.type() in {Item.InputEdge, Item.InclusionEdge, Item.EquivalenceEdge}
                 f2 = lambda x: Identity.Neutral in x.identities()
                 for node in bfs(source=target, filter_on_edges=f1, filter_on_nodes=f2):
                     if node.type() is Item.ComplementNode:
                         # We found a complement node along the path, so any input to this intersection node,
                         # would cause the complement node to identify itself as a value-domain, but in OWL 2 QL
                         # it is not possible to construct complement of value domain expressions.
                         raise ProfileError('Complement of a value-domain expression is forbidden in OWL 2 QL')
Exemplo n.º 15
0
 def __call__(self, node):
     '''
     if (('AttributeIRINode' in str(type(node))) or ('RoleIRINode' in str(type(node)))):
         if node.isFunctional():
             raise ProfileError('Functionality of roles and attributes is forbidden in OWL 2 QL')
     '''
     if isinstance(node, OntologyEntityNode) or isinstance(
             node, OntologyEntityResizableNode):
         if node.iri and node.iri.functional:
             raise ProfileError(
                 '({}) Functionality of roles and attributes is forbidden in OWL 2 QL'
                 .format(str(node.iri)))
Exemplo n.º 16
0
 def __call__(self, node):
     '''
     if ('RoleIRINode' in str(type(node))):
         if node.isReflexive():
             raise ProfileError('Reflexivity of roles is forbidden in OWL 2 RL')
     '''
     if isinstance(node, OntologyEntityNode) or isinstance(
             node, OntologyEntityResizableNode):
         if node.iri:
             if node.iri.reflexive:
                 raise ProfileError(
                     '({}) Reflexivity of roles is forbidden in OWL 2 RL'.
                     format(str(node.iri)))
Exemplo n.º 17
0
 def __call__(self, node):
     if ('RoleNode' in str(type(node))):
         if node.isInverseFunctional():
             raise ProfileError(
                 'Inverse Functionality of roles is forbidden in OWL 2 QL')
Exemplo n.º 18
0
    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.ConceptIRINode:
                    if source.iri and (source.iri.isOwlThing()
                                       or source.iri.isTopObjectProperty()
                                       or source.iri.isTopDataProperty()):
                        raise ProfileError(
                            'Inclusion axioms involving a TOP predicate 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.ConceptIRINode:
                    if target.iri and (target.iri.isOwlThing()
                                       or target.iri.isTopObjectProperty()
                                       or target.iri.isTopDataProperty()):
                        raise ProfileError(
                            'Use of inclusion axioms involving a TOP predicate 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))
Exemplo n.º 19
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.InputEdge:
         if target.type() is Item.EnumerationNode:
             if source.identity() is Identity.Value:
                 raise ProfileError(
                     'Enumeration of values is forbidden in OWL 2 RL')
Exemplo n.º 20
0
 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))
Exemplo n.º 21
0
 def __call__(self, node):
     if node.type() is Item.ValueDomainNode:
         if node.datatype not in Datatype.forProfile(OWLProfile.OWL2QL):
             raise ProfileError(
                 'Datatype {} is forbidden in OWL 2 QL'.format(
                     node.datatype.value))
Exemplo n.º 22
0
 def __call__(self, source, edge, target):
     if edge.type() is Item.SameEdge:
         raise ProfileError(
             'Usage of SameIndividual axiom is forbidden in OWL 2 QL')
Exemplo n.º 23
0
 def __call__(self, node):
     if ('RoleNode' in str(type(node))):
         if node.isTransitive():
             raise ProfileError(
                 'Transitivity of roles is forbidden in OWL 2 QL')
Exemplo n.º 24
0
 def __call__(self, node):
     if node.type() in {Item.DatatypeRestrictionNode, Item.FacetNode}:
         raise ProfileError(
             'Usage of {} operator is forbidden in OWL 2 RL'.format(
                 node.shortName))