Reasoning over OWL cardinality restriction - owl

I think I still have a fundamental misunderstanding of OWL axioms :(.
Here is a small test ontology I created:
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix : <http://foobar.com/test/> .
: a owl:Ontology .
:prop1 a owl:DatatypeProperty .
:prop2 a owl:DatatypeProperty .
:Class1 owl:equivalentClass [
a owl:Restriction ;
owl:onProperty :prop1 ;
owl:cardinality "1"^^xsd:int
] .
:Ind1 a owl:NamedIndividual ;
:prop1 "value1"^^xsd:string .
:Class2 owl:equivalentClass [
a owl:Restriction ;
owl:onProperty :prop2 ;
owl:minCardinality "1"^^xsd:int
] .
:Ind2 a owl:NamedIndividual ;
:prop2 "value2"^^xsd:string .
When I run the Hermit reasoner in Protege over this, I get the expected result with :Ind2, that is it is a member of :Class2. But I am not getting the same for :Ind1 with regards to being a member of :Class1.
I am suspecting that this has to do with open world assumption and that it is possible that :Ind1 might still have another :prop1 assertion. So couple of questions:
Have I diagnosed the problem correctly?
Can I get an example of how I can get my goal for hermit to reason that :Ind1 is a member of :Class1 without explicitly making the assertion?
Thanks

Premise
OWL semantics is defined under open-world assumption, so you can't check if the cardinality for a certain property is exactly N, because there may be other property instances even if not declared.
More precisely, these are the checks that you can do:
Cardinality check
Possible answers
Sound
Complete
At-least N
Yes (if N or more)I don't know (otherwise)
Yes
No
Exactly N
No (if N+1 or more)I don't know (otherwise)
Yes
No
At-most N
No (if N+1 or more)I don't know (otherwise)
Yes
No
Solution
You can check if a cardinality is exactly 1 only if you explicitly state that "value1" is the only value for :Ind1. In this case :Ind1 will be part of :Class1.
In FOL:
∀x.(R(Ind1, x) → x = "value1")
In DL:
∃R⁻.{Ind1} ⊑ {"value1"}
In OWL2 (not tested):
:Ind1
a owl:NamedIndividual ;
a [ a owl:Restriction ;
owl:onProperty :prop1 ;
owl:allValuesFrom [ a rdfs:Datatype ;
owl:oneOf ( "value1"^^xsd:string )
]
] .

Thanks to #horcrux for providing the hint. What worked finally is to also declare the properties as owl:FunctionalProperty. Editing the property declarations to:
:prop1 a owl:DatatypeProperty, owl:FunctionalProperty .
:prop2 a owl:DatatypeProperty, owl:FunctionalProperty .
This does not require adding additional restrictions to each individual declaration.

Related

Using only constraint in owl leads to inconsistency

I am trying to model the following situation:
A degree may be Bachelor or Master
A student may be BachelorStudent or MasterStudent
A degree may have students: Bachelor degrees only have BachelorStudents and viceversa.
I want to experiment with the usage of the "only" restriction, therefore I have defined Bachelor, for example, as equivalent to "has only BachelorStudent".
Therefore, I generated the following code using Protegé:
:has rdf:type owl:ObjectProperty ;
rdfs:domain :Degree ;
rdfs:range :Student .
:Bachelor rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :has ;
owl:allValuesFrom :BachelorStudent
] ;
rdfs:subClassOf :Degree ;
owl:disjointWith :Master .
:BachelorStudent rdf:type owl:Class ;
rdfs:subClassOf :Student ;
owl:disjointWith :MasterStudent .
:Degree rdf:type owl:Class ;
owl:disjointWith :Student ;
owl:disjointUnionOf ( :Bachelor
:Master
) .
:Master rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :has ;
owl:allValuesFrom :MasterStudent
] ;
rdfs:subClassOf :Degree .
:MasterStudent rdf:type owl:Class ;
rdfs:subClassOf :Student .
:Student rdf:type owl:Class ;
owl:disjointUnionOf ( :BachelorStudent
:MasterStudent
) .
However, this leads to an inconsistency when I launch the reasoner. The provided explanation is the following:
I cannot figure out what I am doing wrong. Am I misunderstanding the use of "only", or are there any other mistakes?
The problem is the following: with the axiom:
Master EquivalentTo has only MasterStudent
it follows that things that do not have the has property are classified as Master (has only MasterStudent contains the things that do not have the has property at all). If this sounds strange, think of the class hasChild only Person. This class identifies the things such that, if they have children, then the children are people. Clearly, people belong to this class, even if they do not have children.
The same is true for Bachelor. So, if a thing does not have the has property, it must belong to both Bachelor and Master. But if such a thing existed, then it would violate the disjointness relation between Bachelor and Master. So we must conclude that everything has the has property. This means that everything is a Degree (because of the domain of has) and is related to a Student (because of the range of has). So there exists students, and since everything is a Degree, these students are degrees, which violates the disjointness between Student and Degree.
Now, the problem with your model is that you use an equivalence axiom. You should instead use a subclass relation, and add that all degrees must have the has relation with at least some students, like this:
Master SubClassOf has only MasterStudent
Master SubClassOf has some Student
Bachelor SubClassOf has only BachelorStudent
Bachelor SubClassOf has some Student
or even, if you want it more constrained:
Master EquivalentTo (has only MasterStudent and has some Student)
Bachelor EquivalentTo (has only MasterStudent and has some Student)

How do owl and rdfs property domain range work?

I am trying to understand the semantics of rdfs domain and range. Because I am from an object oriented background, I am struggling to understand the semantics and how to validate data against the rdfs statements.
Here is a sample file in turtle format:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix tmpl: <http://template.example.com/>
prefix data: <http://data.example.com/>
tmpl:Thing a owl:Class.
tmpl:Employment rdfs:subClassOf tmpl:TemporalThing.
tmpl:Party rdfs:subClassOf tmpl:Thing.
tmpl:Individual rdfs:subClassOf tmpl:Party.
tmpl:Organisation rdfs:subClassOf tmpl:Party.
tmpl:LimitedLiabilityCompany rdfs:subClassOf tmpl:Organisation.
tmpl:hasCurrentEmployer a owl:ObjectProperty;
rdfs:domain tmpl:Party;
rdfs:range tmpl:Party.
data:Simon a tmpl:Individual;
skos:prefLabel "Simon S".
data:PtyLtd a tmpl:LimitedLiabilityCompany.
data:Simon tmpl:hasCurrentEmployer data:PtyLtd.
tmpl:Animal a owl:Thing.
data:Beans a tmpl:Animal.
data:Simon tmpl:hasCurrentEmployer data:Beans.
I am using GRAPHDB as my test environment. I would expect the last statement to fail with some sort of message because 'Beans' is an 'Animal' which is not a 'Party'.
Yet, GRAPHDB just accepts the statement.
Any ideas?
EDIT
Based on Stanislav's comment below: While An inference engine might not have a problem with this, we can use the domain and range for error checking in an application.
As said in the comments, you misunderstood the semantics of domain and range.
P rdfs:domain D
P rdfs:range R
mean that if a statement s P o holds, then (with a reasoner running), it could be inferred that s rdf:type D and o rdf:type R.
Domain and range are never restrictions on the the property. That has to be clear.
To understand how things work, check for examplem OWL direct semantics for object properties here.

Member of an owl:Class versus owl:NamedIndividual

Is it right, that in OWL-DL, if some :x has an rdf:type of something which is an owl:Class, e.g. :Car
:Car rdf:type owl:Class .
:x rdf:type :Car .
or equivalent
:Car a owl:Class .
:x a :Car .
it cannot be deduced, that :x must be an owl:(Named)Individual, thus one have to specify that additional fact always manually?
:x a :Car ;
a owl:NamedIndividual ;
:hasType :Ford ;
:hasColor "red" .
OWL and RDF are different things. OWL ontologies can be represented in RDF, by following the rules specified in the OWL 2 Web Ontology Language
Mapping to RDF Graphs document. If you have a look in there, the ways that owl:NamedIndividual are used are:
If an ontology contains the axiom:
Declaration( NamedIndividual( *:a ) )
then the RDF mapping contains the triple:
T(*:a) rdf:type owl:NamedIndividual .
and similarly, if an RDF mapping contains:
*:x rdf:type owl:NamedIndividual .
then the ontology contains
Declaration( NamedIndividual( *:x ) )
(and there's one more case for annotated axioms, but it's essentially the same).
In looking though some more of the semantics documents, I don't see any other places (except for enumerated class expressions) that permit adding an x rdf:type owl:NamedIndividual RDF triple or inferring NamedIndividual(x).

owl override property restriction in subclass

My task is to construct two classes in owl. The Base class describes resources that contain several properties e.g. p1, p2 and p3. The other class, the Sub, shall describe resources similar to the Base class with the restriction, that they do not contain one of its properties, e.g. p1, but only p2 and p3. For example, the class Car would describe vehicles that contains some properties and one of them is 'hasMotor'. The class Bicycle would also describe vehicles with the restriction, that they do not have motor.
I use cardinality restrictions to define such classes:
#prefix : <http://sample.org/test#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix xml: <http://www.w3.org/XML/1998/namespace> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#base <http://sample.org/test> .
<http://sample.org/test> rdf:type owl:Ontology ;
owl:versionInfo "0.2"^^xsd:string .
:p1 rdf:type owl:DatatypeProperty .
:p2 rdf:type owl:DatatypeProperty .
:p3 rdf:type owl:DatatypeProperty .
:Base rdf:type owl:Class ;
rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty :p3 ;
owl:someValuesFrom xsd:string
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :p2 ;
owl:someValuesFrom xsd:string
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :p1 ;
owl:someValuesFrom xsd:string
] .
:Sub rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:intersectionOf ( :Base
[ rdf:type owl:Restriction ;
owl:onProperty :p1 ;
owl:qualifiedCardinality "0"^^xsd:nonNegativeInteger ;
owl:onDataRange xsd:string
]
)
] .
But the Sub class is concluded by Pellet reasoner to be equivalent to Nothing. How should the two mentioned classes be described in owl?
What the axioms mean…
But I cannot understand the inference results produced by Pellet
reasoner. The restriction on the existence of the property seems not
to work. How can I define such a class?
You haven't said what the inference results that Pellet produces are, so it's hard to explain them in particular. But, we can still take a look at what your axioms are saying. OWL classes are really like sets, and the restrictions that you're defining are making assertions about the elements of those sets. When you say, for instance, that
Base &sqsubseteq; ∃prop.String
What you're saying is that
1. If some x is a Base, then there is some String s such that prop(x,s).
Now, you have two more axioms:
Sub &sqsubseteq; Base
Sub &sqsubseteq; =0 prop.String
These say that
2. If some x is a Sub, then x is also a Base.
3. If some x is a Sub, then there are exactly zero Strings s where prop(x,s).
…and why Sub is a subclass of everything else.
Moreover could you please explain why the Sub class is inferred to be a subclass of ObjProp.
Your ontology isn't inconsistent, but you do have the typically undesirable state of affairs that one of your classes, Sub, can't have members. Why is this the case? Well, suppose some x is a Sub. Then, because x is a Sub, it has exactly zero strings. Of course, every Sub is also a Base, so x is also a Base. Since it's a Base, then it must have at least one string. It can't have zero and at least one, so we can't actually have any instances of Sub. Since Sub is the empty class (i.e., equivalent to owl:Nothing) it's a subclass of every other class.

DL query for individuals not connected to others by a property

I have an OWL ontology with three interconnected individuals: a, b, and c, and also has two isolated individuals x, and y.
interconnected individuals:
have at least one outbound object property assertion. e.g.: a hasRelationWith b; or
have at least on inbound object property assertion e.g.: such c, as b hasRelationWith c.
isolated individuals:
have zero outbound object property assertion e.g.: x hasRelationWith [no individual]; and
have zero inbound object property assertion e.g.: such x, as [no individual] hasRelationWith x.
Is it possible to classify (by logical inference, not by enumeration) all the isolated individuals using a DL Query (in Protégé 4.3, if it makes a difference), and if it is possible, how do I do it?
My intuitive guess is something like: (hasRelationWith min 0 Thing) exclude (hasRelationWith min 1 Thing), but DL-Query seems not supporting Set Subtraction syntax...
UPDATE: The following SPARQL can make it, although it cannot be used within class definition.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX my: <http://localhost:8080/ontology/untitled-ontology-26#>
SELECT DISTINCT ?src_obj
WHERE {
?src_obj a owl:NamedIndividual .
minus {?src_obj my:hasRelationWith ?target_obj}
minus {?target_obj my:hasRelationWith ?src_obj}
}
You can query about what's logically provable. That means that if you can infer that some individual isn't related to any others by some property, you can ask about it. For instance, if you have disjoint classes Cat and Dog, so that nothing can be an instance of both, and you have a Person jim who also has the additional type hasPet only Cat and Dog, then a reasoner can infer that jim hasPet exactly 0.
In the DL query language, you can also use inverse properties. The previous example showed that jim has no pets (i.e., is an instance of hasPet exactly 0). You could ask for animals that aren't the pets of anyone by asking for instances of inverse hasPet exactly 0. For instance, if you add disjoint subclasses of Person, ThisKind and ThatKind, and say that missy the Cat inverse hasPet only ThisKind and ThatKind, then a reasoner can infer that no one is related to missy by the hasPet property. An ontology for these two examples is given at the end of this answer.
For your particular query, you just combine two class expressions of the forms I've just described:
hasRelationWith exactly 0 and inverse hasRelationWith exactly 0
or, with some parenthesis:
(hasRelationWith exactly 0) and ((inverse hasRelationWith) exactly 0)
It is very important to note, however, that this only returns individuals for which it can be proven that there are no such relations. It's not enough for the data to simply not contain such relations yet. OWL makes the open world assumption, meaning something that isn't explicitly stated or provable isn't assumed to be true or false.
Example ontology
#prefix : <http://www.example.org/cardinality-example#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
:fido a owl:NamedIndividual , :Dog .
:Dog a owl:Class .
:fluffy a owl:NamedIndividual , :Cat ;
a [ a owl:Class ;
owl:intersectionOf ( :ThatKind [ a owl:Restriction ;
owl:allValuesFrom :ThisKind ;
owl:onProperty [ owl:inverseOf :hasPet ]
] )
] .
:ThatKind a owl:Class ;
rdfs:subClassOf :Person ;
owl:disjointWith :ThisKind .
:rover a owl:NamedIndividual , :Dog .
:hasPet a owl:ObjectProperty .
<http://www.example.org/cardinality-example>
a owl:Ontology .
:Person a owl:Class .
:jim a owl:NamedIndividual , :Person ;
a [ a owl:Restriction ;
owl:cardinality "0"^^xsd:nonNegativeInteger ;
owl:onProperty :hasPet
] .
:missy a owl:NamedIndividual , :Cat .
:Cat a owl:Class ;
owl:disjointWith :Dog .
:ThisKind a owl:Class ;
rdfs:subClassOf :Person .

Resources