I am trying to adapt the Mona Lisa exercise in the Wikidata SPARQL tutorial so it will show all the materials used and where they apply.
If I simply do:
SELECT ?painting ?paintingLabel ?material ?materialLabel
WHERE
{
?painting p:P186 [ ps:P186 ?material].
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
FILTER (?painting = wd:Q12418)
}
then I will see the 3 materials that make up the painting.
If I now edit that query to include P518 (applies to part), I only see the 2 materials that have the P518 qualifier:
SELECT ?painting ?paintingLabel ?material ?materialLabel ?appliesTo ?appliesToLabel
WHERE
{
?painting p:P186 [ ps:P186 ?material; pq:P518 ?appliesTo].
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
FILTER (?painting = wd:Q12418)
}
How can I handle the fact that the P518 qualifier is optional?