William Kinaan
William Kinaan

Reputation: 28799

Sparql query to get all classes that are subclass of a "property class"

I need to "annotate" some classes by adding a property to them. I need to do that in order to let the view layer of my application extract the correct classes.

What I have done is:

create an object property called uiProperty and edit these classes to make them subclass of this class:

uiProperty some

So the final OWL code for my classes is something like this:

rdfs:subClassOf owebs:RealEstate ,
                                [ rdf:type owl:Restriction ;
                                  owl:onProperty owebs:uiProperty ;
                                  owl:someValuesFrom owl:Thing
                                ] ;

Now I want to build a sparql query to get these classes. I did the following:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owbes: <http://www.isep.org/desco/2015/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT $uri $label WHERE {
    $uri rdfs:subClassOf owbes:RealEstate.
    $uri rdfs:subClassOf $x.
    $x owl:onProperty owbes:uiProperty.
    $uri rdfs:label $label
}

The problem

The result of that query is too many classes. The same class is being repeated many times. For example:

enter image description here

My question

Why did that happen? and how to solve it?

Upvotes: 1

Views: 2173

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85843

I need to "annotate" some classes by adding a property to them. I need to do that in order to let the view layer of my application extract the correct classes.

That's actually what annotation properties, such as rdfs:label, are for. You can define your own annotation properties, and then retrieve the classes with SPARQL more directly by querying for those. For instance, here's an ontology with three special classes:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="urn:ex:"
    xmlns:owl="http://www.w3.org/2002/07/owl#">
  <owl:Ontology rdf:about="http://www.semanticweb.org/taylorj/ontologies/2015/5/untitled-ontology-45"/>
  <owl:Class rdf:about="urn:ex:C">
    <j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
  </owl:Class>
  <owl:Class rdf:about="urn:ex:A">
    <j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
  </owl:Class>
  <owl:Class rdf:about="urn:ex:B"/>
  <owl:AnnotationProperty rdf:about="urn:ex:isSpecialClass"/>
</rdf:RDF>

Upvotes: 4

Related Questions