Search code examples
sparqlprotege

Sparql use filter with selecting invidual


I want to retrieve all movies that actor play in. I'm not sure how to specify for which actor(individual in protege) I want results. Below code returns empty table.

PREFIX f: <http://imdb.com/movie.owl#>

SELECT ?title
WHERE {
    ?movie a f:Movie .
    ?movie f:Title ?title .
    ?actor a f:Actor .
    ?actor f:playsIn ?movie .
    FILTER(?actor = "Actor_1")
}

Solution

  • OWL individuals are identified by IRIs, thus, you have to use the full or prefixed IRI in the query and not a string literal:

    PREFIX f: <http://imdb.com/movie.owl#>
    
    SELECT ?title
    WHERE {
        ?movie a f:Movie .
        ?movie f:Title ?title .
        ?actor a f:Actor .
        ?actor f:playsIn ?movie .
        FILTER(?actor = <http://imdb.com/movie.owl#Actor_1>)
    }
    

    Update

    As @Joshua Taylor correctly pointed out, if SPARQL 1.1 is supported you should use the VALUES feature which is probably more what is intended here compared to a FILTER:

    PREFIX f: <http://imdb.com/movie.owl#>
    
    SELECT ?title
    WHERE {
        VALUES ?actor { f:Actor_1 }
        ?movie a f:Movie ;
               f:Title ?title .
        ?actor a f:Actor ;
               f:playsIn ?movie .
    
    }