Search code examples
sparqlontologyprotege

Building a SPARQL query


I need to create a SPARQL query that gives me all the TopicItems contained in a Topic, in the following schema, but I don't know how to do that. enter image description here

There is an inverse ObjectProperty named "ContainedIn", I think I must use it, but I don't know exactly how.


Solution

  • You do not need to use any inverse property, as you can place SPARQL variables in any position in a triple pattern. Just supply a variable for the object in your triple pattern:

    SELECT ?topicItem
    WHERE {
        <...> slo:consistsOf ?topicItem .
    }
    

    where <...> needs to be replaced with the IRI of the topic you want to examine.

    EDIT: I have omitted the prefix declaration here; as you were already using the prefix slo, I presumed you had already successfully declared it somehow. Of course, a prefix declaration needs to be added unless the SPARQL endpoint somehow knows slo as a pre-defined prefix.