Alba banner

Reusing the album amicorum Jacob Heyblocq

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:

1) HTML facebook based on the Wikimedia Commons API

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.

2) SPARQL query on Wikidata

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

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:

3) HTML facebook based on the Wikidata SPARQL service with a JSON response

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 <>.}
    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.

4) Wikidata SPARQL + HTML-embed via iframe

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>
        <title>Facebook of contributors to the album amicorum Jacobus Heyblocq - Wikidata SPARQL + HTML iframe</title>
    	<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="" referrerpolicy="origin" sandbox="allow-scripts allow-same-origin allow-popups"></iframe>

This results into a plain, unstyled facebook in HTML looking like this: styling

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:

About the author

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

Reusing this article

This text of this article is available under the Creative Commons Attribution CC-BY 4.0 License.