Reputation: 177
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")
}
Upvotes: 0
Views: 134
Reputation: 8465
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>)
}
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 .
}
Upvotes: 4
Reputation: 2431
You don't need a filter in this case. You can just include the individual in a triple pattern:
PREFIX f: <http://imdb.com/movie.owl#>
SELECT DISTINCT ?title
WHERE {
?movie a f:Movie .
?movie f:Title ?title .
?actor a f:Actor .
<http://imdb.com/movie.owl#Actor_1> f:playsIn ?movie .
}
This query is not just shorter but will have better performance when run against a bigger data set.
And of course, you don't need the whole URI in case you declared the prefix:
SELECT DISTINCT ?title
WHERE {
?movie a f:Movie .
?movie f:Title ?title .
?actor a f:Actor .
f:Actor_1 f:playsIn ?movie .
}
Upvotes: -1