This section is about reusing AAJH content (data & images, see project page) that is stored in the Wikimedia infrastructure (= Wikidata + Wikimedia Commons + Wikipedia) in other (non-Wiki) sites, platforms, scripts, code, software etc.
Olaf Janssen, May 2021
ยป See the corresponding page on Dutch Wikipedia for additional context & explanations (in Dutch).
Dozens of people (see the bottom of that page, at Index op auteursnamen) contributed to the 17th century album amicorum of Jacob Heyblocq. We would like to make a photo gallery/facebook (Dutch: smoelenboek) of these persons, as far as images of those persons are known (on Commons).
We can do this in multiple ways:
Using its REST API, we want to mimick (parts of) the Category:Contributors to the album amicorum Jacobus Heyblocq on Wikimedia Commons. This category looks like this (d.d. 8-12-2020)
From the JSON response of the API and using this Python script we can generate a basic HTML image gallery/smoelenboek of contributors. The resulting HTML page looks like this (d.d. 12-05-2021) :
The disadvantage of this approach: Wikimedians can adjust categorizations on Commons as they see fit. As a result, images can disappear from the above API call, or multiple images of 1 particular contributor can appear in the JSON response. In other words, the number of images in the resulting facebook may change, without one noticing.
Update 12-05-2021: images have indeed disappeared from the category between 8-12-2020 and 12-05-2021, as can be seen by comparing the above screenshots with those timestamps.
In the Wikidata item Album amicorum of Jacobus Heyblocq (1623-1690), rector of the Latin school in Amsterdam (Q72752496), all contributors to this album are included in the property contributor to the creative work or subject (P767). As a result, we can gather all those persons using the SPARQL query below and then display their images/faces in a ready-made gallery in the Wikidata interface
#defaultView:ImageGrid{"hide":["?gender","?portrait"]}
SELECT DISTINCT ?contributorDescription ?contributor ?contributorLabel ?gender ?portrait WHERE {
BIND(wd:Q72752496 as ?album)
?album wdt:P767 ?contributor.
?contributor wdt:P21 ?gender.
OPTIONAL{?contributor wdt:P18 ?image.}
BIND (wd:Q82985930 as ?maledummy)
BIND (wd:Q82992173 as ?femaledummy)
?maledummy wdt:P18 ?maledummyimage.
?femaledummy wdt:P18 ?femaledummyimage.
BIND(IF(?gender=wd:Q6581072,?femaledummyimage,?maledummyimage) as ?dummyimage). #Choose the dummyimage dependent on gender (female/male)
BIND(IF(BOUND(?image), ?image,?dummyimage) as ?portrait). #If no image is known, substitute the dummy image
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,nl". }
}
ORDER BY DESC (?image)
Here, via Q82985930 + ?maledummyimage and Q82992173 + ?femaledummyimage, male and female dummy images are inserted for the male resp. female album contributors whose images are not (yet) known in Wikimedia Commons.
The facebook resulting from the above query looks like this:
When running a SPARQL query in the Wikidata query interface, we can have the result displayed directly in that interface, as shown above. However, we can also request the search result as a JSON response and then build a custom/DIY interface with it ourselves. We do this as follows:
1) Using the SPARQL query below, we first request some data about the album contributors directly in the Wikidata query interface
SELECT DISTINCT ?contributor ?contributorLabel ?contributorDescription ?image ?commonscat ?wparticleNL WHERE {
BIND(wd:Q72752496 as ?album)
?album wdt:P767 ?contributor.
?contributor wdt:P18 ?image.
OPTIONAL{?contributor wdt:P373 ?commonscat.}
OPTIONAL{?wparticleNL schema:about ?contributor.
?wparticleNL schema:isPartOf <https://nl.wikipedia.org/>.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
}
ORDER BY ?contributorLabel
So we request
of every contributor, because we want to display this data in our DIY interface.
2) Once we have checked that the query and search results are OK, we then request the same response in JSON:
3) With this JSON we can now use this Python script to create this simple HTML photo gallery/smoelenboek.
The facebook made above can also be embedded in an HTML page by means of an HTML iframe. The basic code for that looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Facebook of contributors to the album amicorum Jacobus Heyblocq - Wikidata SPARQL + HTML iframe</title>
</head>
<body>
<h1>Facebook of contributors to the album amicorum Jacobus Heyblocq - Wikidata SPARQL + HTML iframe</h1>
<iframe style="position: absolute; height: 100%; width: 100%; border: none" src="https://query.wikidata.org/embed.html#%23defaultView%3AImageGrid%7B%22hide%22%3A%5B%22%3Fgender%22%2C%22%3Fportrait%22%5D%7D%0ASELECT%20DISTINCT%20%3FcontributorDescription%20%3Fcontributor%20%3FcontributorLabel%20%3Fgender%20%3Fportrait%20WHERE%20%7B%20%0A%20%20BIND(wd%3AQ72752496%20as%20%3Falbum)%0A%20%0A%20%20%3Falbum%20wdt%3AP767%20%3Fcontributor.%0A%20%20%3Fcontributor%20wdt%3AP21%20%3Fgender.%0A%20%20OPTIONAL%7B%3Fcontributor%20wdt%3AP18%20%3Fimage.%7D%0A%0A%20%20BIND%20(wd%3AQ82985930%20as%20%3Fmaledummy)%20%0A%20%20BIND%20(wd%3AQ82992173%20as%20%3Ffemaledummy)%20%20%0A%20%20%3Fmaledummy%20wdt%3AP18%20%3Fmaledummyimage.%0A%20%20%3Ffemaledummy%20wdt%3AP18%20%3Ffemaledummyimage.%0A%20%20BIND(IF(%3Fgender%3Dwd%3AQ6581072%2C%3Ffemaledummyimage%2C%3Fmaledummyimage)%20as%20%3Fdummyimage).%20%23Choose%20the%20dummyimage%20dependent%20on%20gender%20(female%2Fmale)%0A%20%20%20%0A%20%20BIND(IF(BOUND(%3Fimage)%2C%20%3Fimage%2C%3Fdummyimage)%20as%20%3Fportrait).%20%23If%20no%20image%20is%20known%2C%20substitute%20the%20dummy%20image%0A%20%20%20%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%2Cnl%22.%20%7D%0A%7D%20%0AORDER%20BY%20DESC%20(%3Fimage)" referrerpolicy="origin" sandbox="allow-scripts allow-same-origin allow-popups"></iframe>
</body>
</html>
This results into a plain, unstyled facebook in HTML looking like this:
We can further develop this HTML iframe approach into a design that fits seamlessly into the pages about the album on the KB website, resulting into an HTML-page looking like this:
In addition to this image gallery, we can also make a list and a cloud of professions (Dutch: beroepenwolk) of the album contributors in the design of the KB website, again based on embedded HTML iframes containing Wikidata SPARQL queries:
Olaf Janssen is the Wikimedia coordinator of the KB, the national library of the Netherlands. He contributes to
Wikipedia, Wikimedia Commons and Wikidata as User:OlafJanssen
This text of this article is available under the Creative Commons Attribution CC-BY 4.0 License.