Search code examples
sparqlontologyprotege

Using the SPARQL Query tab in Protoge to query elements within my own ontology


I have an ontology that I am trying to qrite SPARQL queries for.

I'm using the Ontology IRI (http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology) displayed on the Active ontology tab to define the PREFIX value in the query below:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX chris: <http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#>

SELECT ?class ?activity
    WHERE { ?class chris:hasActivity ?activity }

When I run this nothing is returned, yet when I output the ontology into RDF format I can see instances if what I want to be returned:

<owl:Class rdf:about="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#SportsHallBooking">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#BookableTimetable"/>
        <rdfs:subClassOf>
                <owl:Restriction>
                        <owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
                        <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Badminton"/>
                </owl:Restriction>
        </rdfs:subClassOf>
        <rdfs:subClassOf>
        </rdfs:subClassOf>
        <rdfs:subClassOf>
                <owl:Restriction>
                        <owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
                        <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Football"/>
                </owl:Restriction>
        </rdfs:subClassOf>
</owl:Class>

So I would expect the results to include:

class | activity
SportsHallBooking | Badminton
SportsHallBooking | Football

Yet I get nothing back.


Solution

  • Credit to Stanislav for the answer.

    select * { ?class rdfs:subClassOf [ owl:onProperty chris:hasActivity; owl:someValuesFrom ?activity ] }