How do owl and rdfs property domain range work? - owl

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.

Related

Reasoning over OWL cardinality restriction

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.

Do I put the ontology in blazegraph together with the data?

I'm trying to learn how to use Blazegraph.
I have created an ontology and added it to the database. No problems. Blazegraph seems easy to use.
Now to my question. I notice that if I query the database now, I get triples from the ontology as answers from sparql queries. So if I add data to the same database, the answers from sparql queries will be from the ontology mixed with the data itself.
Should I not keep the ontology in the same database, or how do I avoid mixing the ontology with the data?
To avoid mixing the ontology with the data, you can namespace the ontology. For example,
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#JW>
a foaf:Person ;
foaf:name "James Wales" ;
foaf:mbox <mailto:jwales#bomis.com> ;
foaf:homepage <http://www.jameswales.com> ;
foaf:nick "Jimbo" ;
foaf:depiction <http://www.jameswales.com/aus_img_small.jpg> ;
foaf:interest <http://www.wikimedia.org> ;
foaf:knows [
a foaf:Person ;
foaf:name "Angela Beesley"
] .
<http://www.wikimedia.org>
rdfs:label "Wikimedia" .
rdf, rdfs, and foaf are all ontologies. Instead of bringing all of them into the document, they're declared in the namespace. You can point the namespace to your owl file (or whatever your ontology is in) and use it the same way. Blazegraph will still be able to reason over the graph as long as it can access the ontology definition.

Protege 5; find all classes related by a to-one cardinality to a specific class

I have OWL ontology, Protege 5. I want starting form a source class S, to retrieve all destination classes D where S is related to Ds by means of to-one cardinality through objectProperty i.e S ([0..*] - 1) D despite what is the connecting objectProperty.
In DL, it would be something similar to :
S ⊑ =1r:D;
where S is my source concept, D is a variable concept and r is a variable objectProperty.
First Point:
How to express this in Manchester Syntax to use it in Protege DL query?
Second Point:
For such query, what are the considered types of property restriction that the reasoner will consider when trying to answer the query? e.g cardinality restriction, functional properties, someValuesFrom, allValuesFrom?
Thanks.
You can't write the kind of query that you're asking about in the DL query syntax. The DL query syntax doesn't have any place for variables; all you can write are class expressions, after which you can ask for the individuals in that class, or subclasses or superclasses of the class. So the answer to the first question is that you can't express your query in the Manchester syntax.
For the second point, there may be reasoners that can help you draw a conclusion here. For instance, you might be able to use a reasoner that supports SPARQL queries and write the template of the class expression with variables. You'd end up with something like this (but this is untested):
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
select ?s ?p ?d where {
?s rdfs:subClassOf [ a owl:Restriction ;
owl:qualifiedCardinality "1"^^xsd:nonNegativeInteger ;
owl:onProperty ?p ;
owl:onClass ?d ]
}
I don't know whether or not most OWL reasoners will be able to handle that though. As mentioned above, the typical task for an OWL reasoner is to look at class expression and determine its subclasses, and superclasses. This is getting more complicated.

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