Meaning of OWL exact cardinality restrictions - owl

I am a newbie coding with the Manchester syntax for OWL. I need to understand the role of exactly. Which of these restrictions is correct:
(hasChild (A or B)) and (hasChild exactly 1 Thing)
(hasChild (A or B)) and (hasChild exactly 2 Thing)
(hasChild (A and B)) and (hasChild exactly 1 Thing)
(hasChild (A and B)) and (hasChild exactly 2 Thing)
Can you explain it when A and B are equivalent, and when they are disjoint?

The meaning of class expressions is defined in section 2.2.3 Class Expressions of the OWL 2 Web Ontology Language Direct Semantics W3C recommendation.
The four class expressions given in the question aren't quite well formed, as I understand the Manchester OWL syntax, as hasChild (A or/and B) really needs to be hasChild some/only (A or/and B). That said, we can still discuss the meaning of the various combinations.
Exact Cardinality Restrictions
The restrictions hasChild exactly 1 Thing and hasChild exactly 2 Thing denote the classes of individuals which are related to exactly one or two other individuals by the hasChild property, respectively. Since the class expression in the restriction is Thing, it is probably more common to see the versions without a class: hasChild exactly 1 and hasChild exactly 2.
Universal or AllValuesFrom Restrictions
The expression hasChild only X denotes the class of individuals which are such that if they are related to any other individual by the hasChild property, then the other individual is an instance of X. It does not impose any constraint that there are such individuals, but only that if there are any, then they must be Xs.
Existential or SomeValuesFrom Restrictions
The expression hasChild some X denotes the class of individuals which are related to at least one other individual that is an X by the hasChild property. It does not impose any constraint that every other individual related by the hasChild is an X, just that at least one is.
The meaning of the expressions
The class expressions in the problem aren't well formed at the moment, and should either be hasChild some (A or/and B) or hasChild only (A or/and B). This means that there are a number of cases to consider, but fortunately some of them condense down.
If A and B are equivalent
If A and B are equivalent, then both (A or B) and (A and B) are equivalent to A and to B. This means that the expressions in the question can be simplified into two cases, depending on whether the restriction on the left hand side should be some or only.
(hasChild some A) and (hasChild exactly 1 Thing)This class expression denotes the class of individuals which are related by the hasChild property to at least one individual of type A, and that are related to exactly one other individual by the hasChild property (and by the left side, that one individual must be that individual of type A).
(hasChild some A) and (hasChild exactly 2 Thing)This class expression denotes the class of individuals which are related by the hasChild property to at least one individual of type A, and that are related to exactly two individuals by the hasChild property (and by the left side, one of these individuals must that individual of type A).
(hasChild only A) and (hasChild exactly 1 Thing)This class expression denotes the class of individuals which are related by the hasChild property only to individuals of type A, and that are related to exactly one other individual by the hasChild property (and by the left side, that one individual must be of type A).
(hasChild only A) and (hasChild exactly 2 Thing)This class expression denotes the class of individuals which are related by the hasChild property to some individual of type A, and that are related to exactly two individuals by the hasChild property (and by the left side, both of these individuals must that individual of type A).
If A and B are disjoint
If A and B are disjoint, then the class expression A and B denotes the empty class, since nothing can be both an A and a B. That means that that four of the cases are unsatisfiable.
The cases that involve hasChild some (A and B) are unsatisfiable, because there are no A and Bs for anything to be related to. There are two such cases:
(hasChild some (A and B)) and (hasChild exactly 1 Thing)
(hasChild some (A and B)) and (hasChild exactly 2 Thing)
The combination of only (A and B) and exactly n is unsatisfiable, since (as long as n is not 0), it says that an individual must be related to exactly n things, and that each of those n things must be an A and B (of which there can be none. There are two such cases:
(hasChild only (A and B)) and (hasChild exactly 1 Thing)
(hasChild only (A and B)) and (hasChild exactly 2 Thing)
The remaining cases are all fairly straightforward, given the meaning of some and only. Though there are four class expressions, there are only two distinct classes.
(hasChild only (A or B)) and (hasChild exactly 1 Thing)
(hasChild some (A or B)) and (hasChild exactly 1 Thing)
This is the class of things that have exactly one child, which must be an A or a B.
(hasChild only (A or B)) and (hasChild exactly 2 Thing)
(hasChild some (A or B)) and (hasChild exactly 2 Thing)
This is the class of things that have exactly two children, each of which must be an A or a B.

Related

read OWL 2 Axiom in plain english

I am trying to understand the following axioms of OWL 2 but don't know what kind of axioms they are. here R is role and C is class
∃R ⊑ C
∃R ⊑ ∃R.C
C ⊑ ¬∃R
∃R ⊑ ¬C
As far i think 1 gives information about Range of R,but i am not sure. Thanks
The only way to make sense of these axioms is to understand the semantics of the Description Logic constructors used:
∃R is the short form of ∃R.T (where T refers to the top concept which represents the complete domain). Mathematically
(∃R.T)^I = {x ∈ δ^I | A y exists such that (x, y) ∈ R^I and y ∈ T^I}
This states that ∃R.T represents the set of individuals consisting of x such that x is associated via relation R to at least 1 individual y that is in top (the domain of discourse). If we had ∃R.C rather than T, y will be in C.
C ⊑ D states that all individuals of type C are also of type D. That is C is a subset of D.
∃R ⊑ C means all the individuals linked to at least 1 individual via relation R is a subset of C. That is why ∃R ⊑ C is also known as a domain axiom because it enforces that for all relations (x, y) in R, that x will be of type C.
¬C defines all the individuals that are not of type C in the domain of interpretation.
Going through the rest of these axioms in a similar way will help you to understand their meaning.

OWL restrictions value vs only vs exactly on dataProperty

Suppose we have a class named A, and a DataProperty called hasRestriction. What is the difference between these statements:
A SubClassOf (hasRestriction value 2)
A SubClassOf (hasRestriction exactly 2)
A SubClassOf (hasRestriction only 2)
TL;DR: read AKSW's comments, they are good and concise.
Long version:
Your question is asking how to interpret class expressions in Protégé. Protégé uses the OWL 2 Manchester syntax to describe classes, and Protégé assumes that ontologies are interpreted according to the OWL 2 Direct Semantics. If the property hasRestriction is a DataProperty in Protégé, then it means that hasRestriction denotes a set of pairs (x,y) where x is an individual (an element of the universe of discourse) and y is a data value (like a number, a string, a date). In Protégé, class expressions are used to denote sets of individuals.
In the statements you provide there are three class expressions:
hasRestriction value 2
hasRestriction exactly 2
hasRestriction only 2
The first one, hasRestriction value 2, identifies the set of things that have the property hasRestriction with the value 2. So if x belongs to this class, then (x, 2) belongs to what hasRestriction denotes. If A is a subClass of this class, then a triple x rdf:type A entails the triple x hasRestriction 2.
The second one, hasRestriction exactly 2, identifies the set of things that have exactly 2 values for the property hasRestriction. So if x belongs to this class, then there are two distinct values v and w such that (x, v) and (x,w) belong to what hasRestriction denotes. If A is a subClass of this class, then a triple x rdf:type A entails the triples x hasRestriction _:v and x hasRestriction _:w and _:v owl:differentFrom _:w (I use a quasi-Turtle syntax here).
The third one, hasRestriction only 2 is a syntax error because if hasRestriction is a datatype property, then you must use a datatype expression after the keyword only. For instance, hasRestriction only xsd:integer.
In the second case, a given individual x in class A may have known values for the property hasRestriction. For instance, there could be the triples x rdf:type A, x hasRestriction 1, x hasRestriction 2, in which case, we know that x exactly has 1 and 2 as values for hasRestriction. If, additionally, we know that x hasRestriction 3, then there is a contradiction, because 1, 2 and 3 are three distinct values, while the expression tells us that there must be exactly two.

Why are union, intersection and difference operations called boolean operations in relational algebra?

Why are union, intersection and difference operations of relational algebra called boolean operations?
I found them called that in the first line in section 5.4.1 Boolean operations (Section 5.4 is Relational Algebra and Datalog) in a book named A First Course in DATABASE SYSTEMS by Ullman & Widom.
The statement that you are citing is from the Chapter 5 (Algebraic and Logical Query Languages) of the book “First Course in Database Systems” by Ullman and Widom (Pearson 2013).
In particular, the sections 5.3 and 5.4 of that Chapter treat the language Datalog, which can be used to work on a Relational Data Base, in which a Relation is seen as predicate, not a set (see Section 5.3.1).
In other words, a tuple (x1, x2, ..., xn) of R is seen as the fact that the relation R is true for the arguments specified (x1, x2, ..., xn). In this way one could transform the set operators discussed in the context of Relation Algebra (union, difference, intersection) as rules of Datalog expressed through the use of boolean operators, like AND, NOT, etc.
In fact, you can see that in the same book, in section 2.4.4, they are called Set Operators (as they actually are), so I think the naming of “boolean operators” is due to the fact that they are strictly related to boolean operators and are discussed in the context of a logical view of a database.
The notion of "boolean" relational operations is an idiosyncratic ad hoc distinction/categorization in that book and chapter. The authors identify 3 common relation operators that "can each be expressed simply in Datalog". The next sections at the same level go on to each express some other relational operator. ("Selections can be somewhat more difficult to express in Datalog.") The 3 operators' treatments are similar to each other and different from others' in a certain context-specific "boolean" way. (So it's not a particularly helpful or deep distinction.)
5.4.1 Boolean Operations
The boolean operations of relational algebra--union, intersection, and set
difference--can each be expressed simply in Datalog.
To take the union R ∪ S, [...] As a result, each tuple from R and each tuple of S is put into the answer relation.
To take the intersection R ∩ S, [...] Then, a tuple is in the answer relation if and only if it is in both R and S.
To take the difference R - S, [...] Then, a tuple is in the answer relation if and only if it is in R but not in S.
So the "boolean" is because each relation operator corresponds to a certain boolean operator in that context:
UNION returns tuples that are in one operand OR the other
INTERSECTION returns tuples that are in one operand AND the other
DIFFERENCE returns tuples that are in one operand AND NOT the other
(Datalog also literally uses AND and AND NOT, but OR is implicit.)
More importantly, this can be put another way: If every base relation holds the tuples that make a true proposition (statement) from some associated predicate (sentence template parameterized by attribute names) then every result has a predicate made from its operand predicates, and its value holds the tuples that make a true proposition from that predicate:
U holds tuples where U
V holds the tuples where V
U UNION V holds the tuples where U OR V
U INTERSECTION V holds the tuples where U AND V
U DIFFERENCE V holds the tuples where U AND NOT V
But more than that it's not just that those operators correspond to some boolean propositional logic connectives/nonterminals, but that every relational operator corresponds to a predicate logic connective/nonterminal, every query expression has an associated predicate, and every query result value holds the tuples that make a true proposition from that predicate:
U JOIN V holds the tuples where U AND V
R RESTRICTcondition holds the tuples where U AND condition
U PROJECT A holds the tuples where FORSOME values for all attributes but A, U
U RENAME A A' holds the tuples where U with A replaced by A'
So the book ties those three operators to the syntax & semantics of Datalog, but really all operators can be tied to the syntax & semantics of predicate logic. Which is the language/notation of precision in mathematics, science (including computer science) & engineering (including software engineering.) In fact, that's how we know what a query means. So it's not really that those three operators are in some sense boolean so much as that all relational operators are logical: every relation expression corresponds to a predicate logic expression.
(The three operators are also frequently called the "set operators", since the set that is the body of the result relation arises from the sets that are the bodies of the operand relations according to the set operators by the same names. And that might be a helpful way to group them in your mind or remember them or their names, and no doubt inspired their names. But in light of the correspondence between relation operators and predicate logic connectives/nonterminals and the correspondence between relation expressions and predicate logic expressions and the correspondence between predicates and relation values, the fact that some relation operators are reminiscent of some set operators is totally irrelevant.) (Just like that some operators are reminiscent of boolean operators. Just like that you can make an algebra with "relations" whose bodies are bags instead of sets.)

Exclude individuals that is related by some specific inverse properties

I have some individuals A,B,C,D,E, and two properties P1, P2.
A P1 B
C P1 D
E P2 C
I want to build a Class that only captures A but not C. so I set a Class like,
myClass EquivalentTo: (P1 some owl:Thing) and (P1 only owl:Thing)
myClass EquivalentTo: (P1 some owl:Thing) and (not inverse P2 some owl:Thing)
but all of those tries failed. How can I differentiate the individual A and C?
myClass EquivalentTo: (P1 some owl:Thing) and (P1 only owl:Thing)
fails because the class expression is really equivalent to P1 some Thing. Since every individual is an instance of Thing, the right hand side of the intersection really doesn't add anything.
myClass EquivalentTo: (P1 some owl:Thing) and (not inverse P2 some owl:Thing)
This is actually correct for the description that you gave. You want individuals that have some value for P1 (good), and that are not the P2 value of some other individual. This is the way to describe that.
I think the issue that you're having is that while while your data set doesn't contain any triples of the form
x P2 A
there's nothing in the ontology that says that such a thing is impossible. So you can't be sure that A actually has the type (not inverse P2 some Thing). This phenomenon is known as the open world assumption (OWA). If you search for that, you'll find some other questions on Stack Overflow about OWA in OWL. See, for instance:
Why is this DL-Query not returning any individuals?
Strange query behaviour in OWL!
In this case, if you want to say that A isn't the P2 value of some other individual, you'd probably have to do it manually, by adding a type to A like:
inverse P2 only owl:Nothing
Once you do that, you'll get the results you want:

OWL-DL; determining if an expression is legal

In SHOIN(D) that is equivalent to the DL family used by OWL-DL;
Is this expression legal:
F ⊑ (≤1 r. D) ⊓ (¬ (=0 r. D))
Where F, D are concepts, r is a role. I want to express that each instance of F is related to at most one instance of D through r, and not to zero instances.
In general, how to decide that some expression is legal w. r. t. a specific variation of DL? I thought that using BNF syntax of the variation may be what I'm targeting.
One easy way is to check whether you can write it in Protege. Most of the things that you can write in Protege will be legal OWL-DL. In Protege you can write:
F SubClassOf ((r max 1 D) and not(r exactly 0 D))
Of course, saying that something has at most 1 value, and not exactly one would be exactly the same as saying that it has exactly 1:
F SubClassOf r exactly 1 D
But there are a few things that you'll be able to do in Protege that won't be legal OWL-DL. The more direct way to find out what these are is the standard, specifically §11 Global Restrictions on Axioms in OWL 2 DL. Generally the only problems you might run into is trying to use composite properties where you're not allowed to.
If you don't want to check by hand, then you could try uploading your ontology into the OWL Validator and selecting the OWL2 DL profile.

Resources