Construct a knowledge graph of artists and artworks of the IMMA museum website

May 13, 2022 ยท View on GitHub

This showcase demonstrates the use of SPARQL Anything for constructing a Knowledge Graph from data encoded in HTML pages.

In what follows, fx refers to the following command line

java -jar sparql-anything-<version>-.jar  

Knowledge graph construction pipeline

Step 1: list artists from the catalogue

This query extracts the list of artists from the Web page and build an XML result set with ?artistNickname and ?artistUrl. The SPARQL result set file will be used in the next query to iterate over each one of the artists' pages.

TitleStep 1: list artists from the catalogue
Queryqueries/imma-artists.sparql
Inputhttps://imma.ie/artists/
Outputimma-artists.xml
TypeSELECT
Optionshtml.selector=#az-group
FormatsHTML
LevelNovice

Run the example as follows:

fx -q queries/imma-artists.sparql -o imma-artists.xml -f xml

Step 2: iterate over artists' web pages and create a JSON-LD for each one of them

In this step we use a parametrized query that is able to query an artists' web page and extract relevant metadata. The query is repeated for each value of the SPARQL result set file produced in the previous step. The command generates a JSON-LD for each execution, using the artist nickname as file name (one of the values provided by the result set). Crucially, the JSON-LD files produced will include web pages of the related artworks.

TitleStep 2: iterate over artists' web pages and create a JSON-LD for each one of them
Queryqueries/imma-artist.sparql
Inputimma-artists.xml, ?_artistUrl
Outputartists/*.jsonld
TypeCONSTRUCT
Options
FormatsHTML
LevelNovice

Run the example as follows:

fx -q queries/imma-artist.sparql -i imma-artists.xml -p "artists/?artistNickname.jsonld" -f json

Step 3: Generate the list of artworks

Next, we extract the list of artworks' Web pages from the JSON-LD files of the artists. This is easy as we can simply query the JSON-LD files, loading them in an in-memory dataset via the command-line option -l.

TitleStep 3: Generate the list of artworks
Queryqueries/imma-artworks.sparql
Inputartists/
Outputimma-artworks.xml
TypeSELECT
Options-l
Formats
LevelNovice

Run the example as follows:

fx -q queries/imma-artworks.sparql -l artists/ -o imma-artworks.xml -f xml

Step 4: Generate the list of artworks

Next, we extract data from the artworks' Web pages and build one JSON-LD file each (create folder 'artworks' first).

TitleStep 4: Generate the list of artworks
Queryqueries/imma-artwork.sparql
Inputimma-artworks.xml, ?_artworkUrl
Outputartworks/*.jsonld
TypeCONSTRUCT
Options
Formats
LevelNovice
fx -q queries/imma-artwork.sparql -i imma-artworks.xml -p "artworks/?artworkNickname.jsonld" -f json

Finally, we can load the files into our favourite triple store.

Extract single artists / artworks

These queries can be used to execute only one specific artists/artwork. In addition, they showcase the CLI option -v, used to pass parameter values.

Extract data from a specific artist Web page:

fx -q queries/imma-artist.sparql -v artistNickname=lambert-gene -v artistUrl=https://imma.ie/artists/gene-lambert/ -p "artists/?artistNickname.jsonld" -f json

Extract data from a specific artwork Web page:

fx -q queries/imma-artwork.sparql  -v artworkNickname=naturaleza-desde-la-ventana -v artworkUrl=https://imma.ie/collection/naturaleza-desde-la-ventana/ -p "artworks/?artworkNickname.jsonld" -f json
fx -q queries/imma-artwork.sparql  -v artworkNickname=berry-dress -v artworkUrl=https://imma.ie/collection/berry-dress/ -p "artworks/?artworkNickname.jsonld" -f json