In the following example the classes enter code here :Class3 and :Class4 are inferred by OWL reasoner (eg Pellet) as types of the individual :Ind1:
@prefix : <http://www.semanticweb.org/test/2015/1/ontology#> .
@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://www.semanticweb.org/test/2015/1/ontology> .
<http://www.semanticweb.org/test/2015/1/ontology> rdf:type owl:Ontology .
:Prop1 rdf:type owl:DatatypeProperty .
:Prop2 rdf:type owl:DatatypeProperty .
:Prop3 rdf:type owl:DatatypeProperty .
:Class1 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :Prop1 ;
owl:someValuesFrom xsd:string
] .
:Class2 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :Prop2 ;
owl:someValuesFrom xsd:string
] .
:Class3 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Restriction ;
owl:onProperty :Prop3 ;
owl:someValuesFrom xsd:string
] .
:Class4 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:intersectionOf ( :Class1
:Class2
)
] .
:Class5 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:unionOf ( :Class3
:Class4
)
] .
:Ind1 rdf:type owl:NamedIndividual ;
:Prop2 "prop2" ;
:Prop1 "prop1" ;
:Prop3 "prop3" .
The :Class4 eg is inferred by reasoner based on properties :Prop1 and :Prop2 of the :Ind1.
I need to construct an individual of type :Class4 from the :Ind1, something like this:
:Ind_Class4 rdf:type :Class4
:Ind_Class4 :Prop1 "Prop1"
:Ind_Class4 :Prop2 "Prop2"
I'm looking how to select the properties :Prop1 and :Prop2 of the :Ind1 as the properties of the class :Class4.
I've tried the SPARQL query
select * where {
?s rdf:type :Class4 .
?s ?p ?o .
}
but it returns all properties of :Ind1 - :Prop1, :Prop2 and :Prop3:
:Ind1 :Prop1 "Prop1"
:Ind1 :Prop2 "Prop2"
:Ind1 :Prop3 "Prop3"
If I change ontology as suggested in Answer1:
:Prop1 rdf:type owl:DatatypeProperty ;
rdfs:domain :Class1 .
:Prop2 rdf:type owl:DatatypeProperty ;
rdfs:domain :Class2 .
:Prop3 rdf:type owl:DatatypeProperty ;
rdfs:domain :Class3 .
:Class1 rdf:type owl:Class .
:Class2 rdf:type owl:Class .
:Class3 rdf:type owl:Class .
:Class4 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:intersectionOf ( :Class1
:Class2
)
] .
:Class5 rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:unionOf ( :Class3
:Class4
)
] .
:Ind1 rdf:type owl:NamedIndividual ;
:Prop1 "Prop1" ;
:Prop3 "Prop3" ;
:Prop2 "Prop2" .
then the suggested SPARQL query
select * where {
?p rdfs:domain :Class4 .
?s ?p ?o .
}
returns an empty resultset.
Thanks.
It's not entirely clear what you're asking, since properties don't belong to classes in OWL. Instead, properties can have domains; when a property P has domain D, it means that any time there is a triple x P y , you can infer that x rdf:type D . Now, you could ask for the properties and values for an individual where a domain of the property is some particular class. That is, you could do something like:
select ?property ?value where {
?property rdfs:domain :Class4 .
:individual ?property ?value .
}
However, note one caveat: properties don't have a single domain, and if you're using inference, they'll often have a lot. Remember that "p's domain is D" means (in OWL) that "xpy implies x rdf:type D." Suppose you have a class A and a subclass of it B. Suppose that a domain of a property P is B. That means that whenever xpy , we have that x rdf:type B . But, since B is a subclass of A, that means that it's also the case that x rdf:type A . That means that xpy also implies that x rdf:type A . That, in turn, means that A is a domain of P as well. I point this out, because this means that when you ask
select ?property ?value where {
?property rdfs:domain :Class4 .
:individual ?property ?value .
}
you'll also be getting any properties that have a declared domain that is a subclass of Class4.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.