Reputation: 2372
I am using Protege to create a ontology
Here is the concept of the ontology :
class : Human
dataProperties :
hasName ( Domain: Human)
hasHeight ( Domain: Human)
hasWeight ( Domain: Human)
class : Man - subClassOf Human
dataProperties :
hasWife ( Domain: Man)
I want to use Sparql to Query the Class:Man's all Dataproperties not only (hasWife) , but also (hasName, hasHeight, hasWeight)
Do I need to specify the DataProperties restriction like min:1?
The main goal here is to find If I want to create a individual type Class:Man
How do I find all properties it need ?
Because every man should have a name and height and weight.
Upvotes: 2
Views: 2068
Reputation: 85853
class : Human dataProperties : hasName ( Domain: Human) hasHeight ( Domain: Human) hasWeight ( Domain: Human) class : Man - subClassOf Human dataProperties : hasWife ( Domain: Man)
I want to use Sparql to Query the Class:Man's all Dataproperties not only (hasWife) , but also (hasName, hasHeight, hasWeight)
First, remember that classes don't have properties in OWL. Properties can have domains and ranges, but all that means is that the subject (object) of an assertion is a member of the domain (range). Although there is the notion of class, it's not quite the same as in an (single-dispatch) object oriented programming language, where properties "belong" to classes.
That said, it sounds like you're looking for all properties that have a domain that is Man or a superclass of Man. (Note that I say "a domain", and not "the domain"; properties can have more than one domain. In fact, if you say that a domain of hasWife is Man, then then Human is also a property of hasWife; after all, if you know that hasWife(x,y), you know that x must be a Human.) This isn't too hard:
select ?p where {
?p rdfs:domain ?class .
:Man rdfs:subClassOf* ?class .
}
That says to find values of ?p that have a domain ?class where :Man is connected to ?class by a path of rdfs:subClassOf links. The * notation means that the path can be any length, including zero. WHen the path length is zero, it means that ?class is :Man. You can actually write this query a bit more concisely if you use the ^ operator to make backward paths:
select ?p where {
?class ^rdfs:domain ?p ;
^rdfs:subClassOf* :Man
}
("a domain", because properties can have more than one domain.
Upvotes: 2
Reputation: 2372
Finally got a solution here !
Here is the sparql
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dar: <http://www.darrell.testSub#>
SELECT DISTINCT ?properties ?superclass ?propertyType
WHERE {
dar:Man rdfs:subClassOf* ?superclass.
?properties rdfs:domain ?superclass.
?properties rdf:type ?propertyType
}
But there is still some problem.
Human ( human's properties)
--Man ( man's properties )
--Woman ( woman's properties )
after reasoning, I query about
< ?s rdfs:domain :Human>
It return ( human + man + woman )'s properties
If I use the sparql up there. I can only get ( human + man )'s properties.
Although this is exactly the result what I want but I can't figure it out why.
Upvotes: 0