I want to write a query to fetch triples about entities related to a film. This is the query:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX : <http://dbpedia.org/resource/>
SELECT DISTINCT ?s1 WHERE {
SERVICE <http://dbpedia.org/sparql/> {
?film ?p ?o
FILTER (?film = :Braveheart) .
OPTIONAL {
{
{
{?o ?p2 ?o2 .}
OPTIONAL {
{?o2 ?p21 ?o21}
UNION
{?s21 ?p22 ?o2}
}
}
UNION
{?s1 ?p3 ?o}
}
}
}
}
This query does not fetch results. However, commenting the section
OPTIONAL {
{?o2 ?p21 ?o21}
UNION
{?s21 ?p22 ?o2}
}
generates the results. I want to understand why the OPTIONAL
clause prevents the results from being generated and how I can resolve the issue.