0

In the following example the classes enter code here :Class3 and :Class4 are inferred by OWL reasoner (e.g. 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 e.g. 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.

igor.br
  • 29
  • 7

1 Answers1

2

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 "x p y 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 x p y, 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 x p y 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.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • The class Class1 e.g. should define a class of individuals that provide the property Prop1. The class Class4 should define the class of individuals that provide the property Prop1 from class Class1 as well the Prop2 from class Class2. – igor.br Feb 17 '15 at 21:26
  • @igor.br I'm not sure what you're trying to say. You can define the class of things having some value for a property by saying something like `PetOwner equivalentClass (hasPet some Thing)`, but I'm not sure if that's what you're trying to say. – Joshua Taylor Feb 17 '15 at 21:30
  • The reasoner display in Protege the Class4 as a type of individual Ind1 that provides the properties Prop1 and Prop2. I need to find out how can I get this information either from Model/Graph (I'm using Jena) or with a SPARQL. Changing definition of classes Class1 and Class2 from property restrictions to being domains of properties does not bring the success. The SPARQL you suggested does not return any results. – igor.br Feb 17 '15 at 21:37
  • @igor.br I'm still not clear what exactly the question is. Could you update the question to show what the results you want are. It's OK if you have to create them by hand this time; we'll get a better understanding of what you're trying to get. – Joshua Taylor Feb 17 '15 at 21:38
  • I extended the original question with expected results as well with the ontology defining domains of properties. – igor.br Feb 17 '15 at 22:11