0

Is it possible to query a filter a SPARQL query by the class of one of its properties? I have an ontology which describes films, and I wish to display all films which were filmed in Europe.

The current SPARQL query is as below:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX cinema: <http://example.com/ontologies/cinemachain#>
SELECT ?film ?location
    WHERE { 
        ?film rdf:type cinema:Film .
        ?film cinema:wasFilmedAt ?location .
        FILTER(?location rdfs:subClassOf cinema:Europe) .

}

The first two lines of the where clause give me a list of all films and their locations. How can I use the filter to return me results where the location is a subclass of cinema:Europe?

Alex King
  • 180
  • 6
  • 17
  • "the location is a subclass of cinema:Europe" It seems very unlikely that the location ever would be a subclass of something. After all, "homeMovie wasFilmedAt myHouse" could be true, but myHouse would be an *instance* of Location, not a subclass of Location. Do you mean that you want locations that have a type that is a subclass of Europe? (I'm still not exactly sure what that would mean, since Europe seems like an instance, not a class...) – Joshua Taylor Apr 15 '15 at 18:51
  • In this particular ontology, cinema:Europe is a subclass of cinema:Location. This is so that we can easily identify particular locations by continent. For this filter, I want to find all films who have a location which is a member of Europe. Do you know how I can do this using SPARQL? – Alex King Apr 15 '15 at 20:41

1 Answers1

2

In this particular ontology, cinema:Europe is a subclass of cinema:Location. This is so that we can easily identify particular locations by continent. For this filter, I want to find all films who have a location which is a member of Europe. Do you know how I can do this using SPARQL?

OK, the naming convention is a little bit unusual, but we can work with it. You just need to require that the ?location has a type that is a subclass of Europe (including Europe itself):

select ?film ?location where {
  ?film rdf:type cinema:Film ;
        cinema:wasFilmedAt ?location .
  ?location rdf:type/rdfs:subClassOf* cinema:Europe .
}
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353