Why use owl:Restriction as own:EquivalenceClass's property? - sparql

I just start to learn Semantic Web and have a question about restriction class. I dug a while but haven't found any answer yet.. Any help would be much appreciated!
From text book, I see examples of define restriction class, they are all about to define a anonymous owl:Restriction class bnode and link this bnode with property owl:equivalentClass.
example:
example:restrictionClass owl:equivalentClass [
rdf:type owl:Restriction;
owl:onProperty example:resProp;
owl:someValuesFrom example:resValue.
]
My question is can we define a restriction class directly? Like:
example:restrictionClass rdf:type owl:Restriction;
owl:onProperty example:resProp;
owl:someValuesFrom example:resValue.
What's the advantage to define anonymous owl:Restriction?

No, you can't. The RDF you're seeing is the encoding of the OWL axiom like: EquivalentClasses(C ObjectSomeValuesFrom(p D)). It gets encoded as:
:C owl:equivalentClass [
rdf:type owl:Restriction;
owl:onProperty :p;
owl:someValuesFrom :D .
]
Now, suppose you also had the axiom EquivalentClasses(C ObjectSomeValuesFrom(r E)). That gets encoded as:
:C owl:equivalentClass [
rdf:type owl:Restriction;
owl:onProperty :r;
owl:someValuesFrom :E .
]
Now, if you could apply the abbreviation that you want, you'd get:
:C rdf:type owl:Restriction ;
owl:onProperty :p ;
owl:onProperty :r ;
owl:someValuesFrom :D ;
owl:someValuesFrom :E .
Now there's ambiguity. Which of the following would C be equal to?
ObjectSomeValuesFrom(p D)
ObjectSomeValuesFrom(p E)
ObjectSomeValuesFrom(r D)
ObjectSomeValuesFrom(r E)
From the RDF alone, you don't have a way to tell. You actually need to encode the EquivalentClasses axioms.
Addendum
To address questions from the comments: I used C, p, and D to make the text shorter. Your original RDF snippet is the RDF encoding of the axiom
EquivalentClasses(
example:restrictionClass
ObjectSomeValuesFrom(example:resProp example:resValue)
)
That's what
example:restrictionClass owl:equivalentClass [
rdf:type owl:Restriction;
owl:onProperty example:resProp;
owl:someValuesFrom example:resValue.
]
encodes. example:restrictionClass is the same IRI in both places. The entire blank node is the class expression ObjectSomeValuesFrom(example:resProp example:resValue). Then owl:equivalentClass just relates the two. Note that expressions aren't the same; the classes that they denote are the same. The mapping from OWL ontologies to RDF is given in OWL 2 Web Ontology Language: Mapping to RDF Graphs (Second Edition). Specifically, have a look at Table 1 in 2.1 Translation of Axioms without Annotations where you'll find the rules:
EquivalentClasses( CE1 ... CEn )
------------------------------------
T(CE1) owl:equivalentClass T(CE2) .
...
T(CEn-1) owl:equivalentClass T(CEn) .
and
ObjectSomeValuesFrom( OPE CE )
------------------------------
_:x rdf:type owl:Restriction .
_:x owl:onProperty T(OPE) .
_:x owl:someValuesFrom T(CE) .
When you go in the reverse direction, you can read in the RDF and reconstruct your axiom. But support that the mapping let you do the abbreviation that you're talking about, and you had two equivalent class axioms. You'd end up with ambiguous RDF, since you'd have two owl:onProperty triples, and two owl:someValuesFrom triples.
Maybe an example from arithmetic would help. We know that 4, 2+2, and 1+3 are all expressions that denote the same number. So we can have the axioms:
4 = 2 + 2
4 = 1 + 3
Now suppose that we encode that in RDF with something like:
:four :equals [ rdf:type :sum ; :left :two ; :right :two ] .
:four :equals [ rdf:type :sum ; :left :one ; :right :three ] .
That's nice, and we can reconstruct 4 = 2+2 and 4 = 1+3 from it. Now suppose we tried to move those properties to :four, rather than a blank node related by :equals. We'd end up with:
:four rdf:type :sum .
:four :left :two .
:four :right :two .
:four :left :one .
:four :right :three .
But what axioms is this supposed to represent? You have have four ways of picking a left and right from :four. Which of the following is it supposed to encode?
4 = 2 + 2
4 = 2 + 3
4 = 1 + 2
4 = 1 + 3

Related

SPARQL property paths based on a new property defined in a CONSTRUCT subquery

Given the following schema, "driver-passenger" lineages can be easily seen:
tp:trip a owl:Class ;
rdfs:label "trip"#en ;
rdfs:comment "an 'asymmetric encounter' where someone is driving another person."#en .
tp:driver a owl:ObjectProperty ;
rdfs:label "driver"#en ;
rdfs:comment "has keys."#en ;
rdfs:domain tp:trip ;
rdfs:range tp:person .
tp:passenger a owl:ObjectProperty ;
rdfs:label "passenger"#en ;
rdfs:comment "has drinks."#en ;
rdfs:domain tp:trip ;
rdfs:range tp:person .
Consider the following data:
<alice> a tp:person .
<grace> a tp:person .
<tim> a tp:person .
<ruth> a tp:person .
<trip1> a tp:trip ;
tp:participants <alice> , <grace> ;
tp:driver <alice> ;
tp:passenger <grace> .
<trip2> a tp:trip ;
tp:participants <alice> , <tim> ;
tp:driver <alice> ;
tp:passenger <tim> .
<trip3> a tp:trip ;
tp:participants <tim> , <grace> ;
tp:driver <tim> ;
tp:passenger <grace> .
<trip4> a tp:trip ;
tp:participants <grace> , <ruth> ;
tp:driver <grace> ;
tp:passenger <ruth> .
<trip5> a tp:trip ;
tp:participants <grace> , <tim> ;
tp:driver <grace> ;
tp:passenger <tim> .
Now let a "driver-passenger descendent" be any tp:passenger at the end of a trip sequence where the tp:passenger of one trip is the tp:driver of the next trip
Ex. <ruth> is a descendent of <alice> according to the following sequence of trips:
<trip2> -> <trip3> -> <trip4>.
Question:
How to get the (ancestor,descendent) pairs of all driver-passenger lineages?
Attempt 1:
I initially tried the following CONSTRUCT subquery to define an object property: tp:drove, which can be easily used in a property path. However, this did not work on my actual data:
SELECT ?originalDriver ?passengerDescendent
WHERE {
?originalDriver tp:drove+ ?passengerDescendent .
{
CONSTRUCT { ?d tp:drove ?p . }
WHERE { ?t a tp:trip .
?t tp:driver ?d .
?t tp:passenger ?p .}
}
}
Attempt 2:
I tried to create property path which expresses an ancestor as the driver of a passenger, but I don't think I've properly understood how this is supposed to work:
(tp:driver/^tp:passenger)+
Regarding MWE: Is there some kind of RDF sandbox that would allow me to create an MWE by defining a simple ontology like tp above, along with some sample data? The following "playgrounds" are available but none of them seem to support defining a toy ontology: SPARQL Playground, SPARQL Explorer.
Notes on related content:
This question is directly related to a previous question, but no longer requires saving the paths themselves, a feature not directly supported by SPARQL 1.1.
This answer by Joshua Taylor seems relevant, but doesn't address the identification of specific types of paths, such as the lineages defined above.
This one seems to do the trick:
select ?driver ?passenger where {
?driver (^tp:driver/tp:passenger)+ ?passenger .
filter( ?driver != ?passenger)
}
The filter condition can be removed if you want to also see relationships that lead back to the same person.

Use automatically-assigned blank node with reified data

I'm trying to query a dataset which uses the RDF reification vocabulary, something like this:
myprefix:statement1 rdf:subject myprefix:object1 .
myprefix:statement1 rdf:predicate myprefix:isrelatedto .
myprefix:statement1 rdf:object myprefix:object2 .
myprefix:statement2 rdf:subject myprefix:object2 .
myprefix:statement2 rdf:predicate myprefix:isrelatedto .
myprefix:statement2 rdf:object myprefix:object3 .
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix myprefix: <mydomain#>
select *
from <mydomain>
where {
[ rdf:subject ?first ; rdf:predicate myprefix:isrelatedto ; rdf:object _:1 ] .
[ rdf:subject _:1 ; rdf:predicate myprefix:isrelatedto ; rdf:object ?second ] .
}
Result:
__________________ __________________
| first | second |
|__________________|__________________|
| myprefix:object1 | myprefix:object2 |
|__________________|__________________|
Can I replace the labelled blank node _:1 with the [ ] construction somehow?
EDIT: Should explain that the reason for the question was that in the real use case I have a much more complex query that needs to get a variable number of properties like this (the query is generated dynamically). So what I'm trying to do is get rid of the labelled node so that I don't have to generate unique labels dynamically.
[ ] works when there is at most one reference to it.
Here we have:
... rdf:object _:1
... rdf:subject _:1
so two references to the blank node as currently written.
If you can modify the rest of the query, it may be possible. Whether the intent is clearer is something you'll have to make a judgement on.
Because in the part:
[ rdf:subject _:1 ; ....]
isn't using the outer [ ] blank node for anything so it might be possible to have rdf:object/^rdf:subject as suggested in the comment.
Whether the intent is clearer is something you'll have to make a judgement on.

Numeric properties that are returned as string by SPARQL

I'm having a problem with SPARQL when dealing with numeric data types.
I have an ontology (http://cabas.ugr.es/ontology/ugr) in which I have defined a pair of properties that represent the number of students who are of a particular sex:
<http://cabas.ugr.es/ontology/ugr#hombres>
a owl:DatatypeProperty, owl:FunctionalProperty, rdf:Property ;
rdfs:label
"hombres"#es,
"men"#en ;
rdfs:comment
"Número de estudiantes hombres."#es,
"Number of male students."#en ;
rdfs:range xsd:nonNegativeInteger ;
rdfs:isDefinedBy <http://cabas.ugr.es/ontology/ugr#> ;
owl:sameAs <http://cabas.ugr.es/ontology/ugr#hombres> ;
owl:inverseOf <http://cabas.ugr.es/ontology/ugr#mujeres> ;
ns1:term_status "stable" .
<http://cabas.ugr.es/ontology/ugr#mujeres>
a owl:DatatypeProperty, owl:FunctionalProperty, rdf:Property ;
rdfs:label
"mujeres"#es,
"women"#en ;
rdfs:comment
"Número de estudiantes mujeres."#es,
"Number of female students."#en ;
rdfs:range xsd:nonNegativeInteger ;
rdfs:isDefinedBy <http://cabas.ugr.es/ontology/ugr#> ;
owl:sameAs <http://cabas.ugr.es/ontology/ugr#mujeres> ;
owl:inverseOf <http://cabas.ugr.es/ontology/ugr#hombres> ;
ns1:term_status "stable" .
I have a SPARQL endpoint mounted on Virtuoso (http://cabas.ugr.es:8890/sparql), in which I enter for example the following query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ugr: <http://cabas.ugr.es/ontology/ugr#>
SELECT ?X ?titulacion ?rama ?hombres ?mujeres
WHERE {
?X ugr:Titulación ?titulacion .
?X ugr:RamaConocimiento ?rama .
?X ugr:hombres ?hombres .
?X ugr:mujeres ?mujeres
}
(Which would correspond with this link)
It returns all the records, but the fields "hombres" and "mujeres" returns them to me as if it were a string instead of a numeric value, so for example it is impossible to apply a filter like FILTER (?hombres > 500). Any idea what I'm wrong about?
By the way, the ontology and the resource with the values are accessible through these links:
Ontology:
Turtle Format:
http://cabas.ugr.es/ontology/ugr
http://cabas.ugr.es/ontology/ugr.ttl
RDF/XML Format:
http://cabas.ugr.es/ontology/ugr.rdf
Resource:
Turtle Format:
http://cabas.ugr.es/resources/MatriculasGrado1516
http://cabas.ugr.es/resources/matriculas_grado_1516.ttl
RDF/XML Format:
http://cabas.ugr.es/resources/matriculas_grado_1516.rdf
In order to treat the numbers as numbers, you need to define them as such.
Right now you define them as strings:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91" ;
ns0:mujeres "68" .
To define them as integers, you need to set their type to xsd:integer:
<http://cabas.ugr.es/resources/MatriculasGrado1516#21>
ns0:hombres "91"^^xsd:integer ;
ns0:mujeres "68"^^xsd:integer .
Strings can also be cast to integer in queries, if needed. For example:
FILTER(xsd:integer(?hombres) > 500)

SPARQL: query for a complete list

I have such a query:
CONSTRUCT {
?p a :IndContainer .
?p :contains ?ind .
} WHERE{
:ClassContainer_1 :contains ?class .
?ind a ?class .
BIND (IRI(...) AS ?p) .
}
An individual ClassContainer_1 relates to some classes. I get this classes and try to find individuals for these classes. Then I try to create an IndContainer that should store found individuals (dots are used only for simplification). So, I want to:
Create individual of IndContainer only when individuals for all bindings of ?class have been found;
Create individuals of IndContainer for all possible sets of individuals from ?ind (i.e. when some of ?class has a nuber of individuals).
Is it possible to create such a SPARQL query? Or it is necessary to use some rule engine?
EDIT (add illustration):
Positive example. Have:
test:ClassContainer_1
rdf:type test:ClassContainer ;
test:contains test:Type1 ;
test:contains test:Type2 ;
.
test:Type1_1
rdf:type test:Type1 ;
.
test:Type1_2
rdf:type test:Type1 ;
.
test:Type2_1
rdf:type test:Type2 ;
.
Want to receive:
test:IndContainer_1
rdf:type test:IndContainer ;
test:contains test:Type1_1 ;
test:contains test:Type2_1 ;
.
test:IndContainer_2
rdf:type test:IndContainer ;
test:contains test:Type1_2 ;
test:contains test:Type2_1 ;
.
Negative example: the same as positive except that there is no individuals of class Type2 and so no individuals of IndContainer should be generated.
EDIT 2 (problem essence):
We may look at this problem from the perspective of combination composing. We have two positions (in my example) in each combination. The number of positions is determined by the number of classes each ClassContainer depends on. Each position must be filled in with one individual of a class that correspond to that position. So in my example first position must be filled with one individual of Type1 class, the second - with Type2 class (but the order does not matter). We have two individuals for the first class and one individual for the second class. To get the number of combinations we may use the rule of product from combinatorics - 2*1 = 2, i.e. {Type1_1,Type2_1} - is the first combination and {Type1_2,Type2_1} - is the second combination. For each combination it is necessary to generate IndContainer individual.
If I understand your question correctly, you want a "container" for each class that is contained in a "class container" that contains the individuals that belong to that class. That's not too hard to do, as long as you can construct the IRI of the container from the IRI of the class. Here's some sample data with two classes, A and B, and a few instances (some of just A, some of just B, and some of A and B):
#prefix : <urn:ex:> .
:container a :ClassContainer ;
:contains :A, :B .
:w a :A . # an :A
:x a :A . # another :A
:y a :B . # a :B
:z a :A, :B . # both an :A and a :B
You query is already pretty close. Here's one that works, along with its result:
prefix : <urn:ex:>
construct {
?indContainer a :IndContainer ;
:contains ?ind .
}
where {
:container a :ClassContainer ;
:contains ?class .
?ind a ?class .
bind(IRI(concat(str(?class),"-container")) as ?indContainer)
}
#prefix : <urn:ex:> .
:B-container a :IndContainer ;
:contains :y , :z .
:A-container a :IndContainer ;
:contains :w , :x , :z .

Pellet reasoner crashes when classifying ontology with datatype restriction as pattern

I have an ontology that defines a new data type as pattern restriction on string type. This data type is then used as a property range restriction. Then a class is defined as a restriction on this property:
#prefix : <http://test.com/prop#> .
#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://test.com/prop> .
<http://test.com/prop> rdf:type owl:Ontology .
:MyType rdf:type rdfs:Datatype ;
owl:equivalentClass [ rdf:type rdfs:Datatype ;
owl:onDatatype xsd:string ;
owl:withRestrictions ( [ xsd:pattern "[a-zA-Z]*"
]
)
] .
# Properties
:hasProperty rdf:type owl:ObjectProperty .
:hasValue rdf:type owl:DatatypeProperty .
# Classes
:BaseClass rdf:type owl:Class .
:BaseProperty rdf:type owl:Class .
:MyClass rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:intersectionOf ( :BaseClass
[ rdf:type owl:Restriction ;
owl:onProperty :hasProperty ;
owl:someValuesFrom :MyProperty
]
)
] ;
rdfs:subClassOf :BaseClass .
:MyProperty rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:intersectionOf ( :BaseProperty
[ rdf:type owl:Restriction ;
owl:onProperty :hasValue ;
owl:someValuesFrom :MyType
]
)
] ;
rdfs:subClassOf :BaseProperty .
# Individuals
:Ind1 rdf:type :BaseClass ,
owl:NamedIndividual ;
:hasProperty :Prop1 .
:Prop1 rdf:type :BaseProperty ,
owl:NamedIndividual ;
:hasValue "Maier" .
The Protege crashes while classifying this ontology with Pellet reasoner:
UnsupportedOperationException: null
com.clarkparsia.pellet.datatypes.types.text.RestrictedTextDatatype.applyConstrainingFacet(RestrictedTextDatatype.java:93)
com.clarkparsia.pellet.datatypes.DatatypeReasonerImpl.getDataRange(DatatypeReasonerImpl.java:440)
The FaCT++ reasoner failed with exception:
ReasonerInternalException: Unsupported datatype 'http://test.com/prop#MyType'
uk.ac.manchester.cs.factplusplus.FaCTPlusPlus.getBuiltInDataType(Native Method)
The Pellet seems only to have trouble with the pattern as a restriction. The FaCT++ seems to have trouble with a user defined datatype.
Do I have errors in the ontology or the reasoners are not able to classify such pattern restriction?
The current version of FaCT++ does not support user-defined datatypes. So the report from FaCT++ is correct.
Pellet should support user-defined datatypes, but your definition is incorrect. The owl:equivalentClass construction is a) from the obsolete OWL 1 syntax, that doesn't support datatype definitions, and b) is only valid for classes, not datatypes. I would suggest to use OWL 2 syntax http://www.w3.org/TR/2012/REC-owl2-syntax-20121211/ in your datatype definition.