I created a query to find female artists based on some conditions, and wanted to include pictures to the result of the query so that #defaultView: ImageGrid view shows not only the required data, but also a corresponding image of the artist(P18). I understand that sometimes the image may be absent, so I used an OPTIONAL clause not to lose the data about artists without an image.
However, when default view is set to ImageGrid, I don't get to see all the results. To check all of them I have to switch to Table View.
The query is:
#defaultView:ImageGrid
SELECT distinct
(year(?birthDate) as ?year)
?person
?personLabel
(count(distinct ?notablework) as ?workCount)
(GROUP_CONCAT(DISTINCT ?notableworkLabel; separator="; ") AS ?works )
(sample(?image) as ?imageSample)
?placeOfBirth
?cood
WHERE {
?person wdt:P106 wd:Q483501 .
?person rdfs:label ?personLabel .
FILTER (LANG ( ?personLabel ) = "en" )
?person wdt:P21 wd:Q6581072 .
?person wdt:P569 ?birthDate .
?person wdt:P800 ?notablework .
?notablework rdfs:label ?notableworkLabel .
FILTER (LANG ( ?notableworkLabel ) = "en" )
FILTER(year(?birthDate) > 1899 && year(?birthDate) < 2000)
?person wdt:P27 wd:Q30 .
?person wdt:P6379 wd:Q160236.
OPTIONAL {?person wdt:P18 ?image} .
OPTIONAL {?person wdt:P19 ?country .
?country rdfs:label ?placeOfBirth .
?country wdt:P625 ?cood .
FILTER (LANG ( ?placeOfBirth ) = "en")
}
}
GROUP BY ?person ?personLabel ?placeOfBirth ?cood ?birthDate
HAVING (?workCount >= 3)
ORDER BY ?personLabel
and an OPTIONAL clause I'm talking about is line 30:
OPTIONAL {?person wdt:P18 ?image} .
Query actually retrieves 7 results, But only 3 are shown in an image grid.
Using an OPTIONAL clause, I expected to see all of the 7 results in ImageGrid view, thinking there would be some kind of 'Image is not available' message put instead of the picture, but that didn't happen.
I also thought it has something to do with my browser, but switching from Firefox to Chrome didn't work out.
Is there actually a way to do something like that in SPARQL or the expected layout I described is not generally implemented into the service?
As said by UninformedUser in the comments, you can use the following SPARQL snippet:
According to the SPARQL 1.1 specification:
So if the
?image_variable is matched in the OPTIONAL clause, it will be bind to the?imagevariable. Otherwise a default image will be bind to the?imagevariable.