A step-by-step tutorial to the ArtBase query service

From Rhizome Artbase


Step 1

To access the visual query helper tool, first open up the query service in a new tab or browser window. If you don’t immediately see the query helper tool, click on the lower-case “i” in the top left corner of the toolbar visible immediately below the Rhizome logo. This button will open and close the helper interface.

Step 2

Next step is to select what to query for. To be able to work with the query service efficiently, you need to be moderately acquainted with the way data is structured in the ArtBase. To do this you can refer to the data model documentation, or look at some example pages for items in the database to get an overview of the type of data available to query. In this tutorial, we will search for artist collectives. Translated into LOD syntax, this means we are looking for items connected to the value “collective”.

Step 3

The query helper interface works like a filter. If you click on the Filter button and start typing the term “collective” an auto-suggestion should pop up after a few key strokes. If you’re looking for unknown items connected to known values, you need to “filter” for those values, in this case—“collective”.

A screenshot of the query helper showing filtering for collectives

The query helper will also suggest a property to use with this value. In this case, the auto-suggessted property is not the one you need, but you can easily edit that field to use the correct property, which in this case is “instance of”. This property that allows to filter the data by a particular type of item in the database, in this case collective, but other examples include artworks, variants, people, institutions, etc.

A screenshot of the query helper showing filtering for instances of collectives

Step 4

Once you have created at least one filter, you can “run” your query to see the results. Some results may appear even while you’re typing the filter values, but you won’t get complete results until you hit the big blue “play” button in the toolbar on the left of the helper interface.

A screenshot of the query results shown in a table

Once you click the button, you will get the complete set of results in the space below the helper interface. At this point in time, there appear to be 51 results for artist collectives in the ArtBase. You will also notice that the manual data entry field to the right-hand side of the helper interface has already been pre-filled with some text written in SPARQL. Don’t worry about this field just yet, but be aware this is where you can later do manual editing to create more complex queries.

Step 5

At this point we have some results, but they are only visible with their unique database identifiers and we are missing the labels of these items. To add labels, i.e. human-readable text that is attached to each unique identifier, you can press the blue “tag” icon next to the collective value field.

A screenshot of the query helper interface with the labeling function activated

Once again it’s good to hit the “run” button to ensure all results are displayed correctly. You can now see and read 51 collectives that are recorded in the archive.

A screenshot of the query results shown in a table with labels

Step 6

Next you can choose further attributes to display in the query results. To do so, we will use the “Show” button in the query helpetr interface. Let’s start with members – we want to see who are the members of these collectives. “Show” works only with properties (no need to input values), so you just need to select the correct property, in this case “member”. (Note that you should use “member” and not “member of”, which is a property used to link individuals to their collectives. Since we are filtering for “collectives”, rather than individual people, the correct property to use in this example is “member”. Picking the wrong property at this stage won’t break the query, but simply won’t render any results. When you’re not sure what property to use, try a few and see which one gives you the results you expect.)

A screenshot of the query helper interface with the show members function activated

While you’re choosing attributes, you could also select a further property and see if you get any results. An appropriate one in this case would be “image”, which would show you how many collectives in the ArtBase also have images associated with them.

A screenshot of the query helper interface with the show images function activated

Step 7

A screenshot of the query service results toolbar showing the data visualization dropdown open

Once you’ve selected a few attributes, you will notice that yoru results have grown in number – this is not to say that there are more collectives showing up. Instead, for some collectives there are multiple results (e.g. multiple members), and so these are displayed as new rowes in the results table. This may seem like a duplication of information, but it is simply a function of the table visualization. You could choose to display the results in alternative data visualizations which suit the data better. Choosing the best mode of displaying data is highly dependent on the type of query you are running and the type of information being returned. You can explore alternative data visualizations available for each query by clicking the “eye” icon below the blue “run” button. You will then see a dropdown of various options. The best way to learn useful ways of displaying the data as a new user of the query service is by trial-and-error.

In this case a Tree visualization is a helpful way of giving an overview of all collectives and nesting members below each relevant label.

A screenshot of the query results shown in a tree table visualization

Step 8

Finally, once you’re done filtering data, adding attributes and selecting a mode of display, you may want to download the results, or share them. There are several options to explore in the download and link dropdowns to the right hand side of the results counter. A “CSV file” download for example will allow you to open up and explore the data in a spreadsheet format. Getting a “Short URL to result” will provide you with a link that opens up the query results in full screen mode and can be helpful to share with other users interested in the same data as yourself.

A screenshot of the query service results toolbar showing the download dropdown open

A screenshot of the query service results toolbar showing the link dropdown open









Additional steps towards manual editing

Once you have understood the basic principles of operating with the query helper interface, you could push your expiration of the query service further, by manually editing the SPARQL code.

Lock default view

Once you are happy with the filtered results and selected attributes in your query, you could choose an appropriate visualization mode that best expresses the result. In the case of the collectives example, a Tree or a Graph visualization are appropriate choices. If you want to “lock” this view as default, you can do that by simply typing “#defaultView:[name of visualization mode]” at the start of your query’s SPARQL code. See the example for a Graph visualization below:

A screenshot of the query results shown in a graph visualization

This is helpful if you want to share the results with someone else as a URL link, or embed the results in a webpage. Unless to specify a default view, every time someone opens the link to the query results, they will see the results displayed as a standard table.

Add color

The Graph view is a nice way to represent collectives and their members, but to make it easier for yourself or others to instantly spot the main subject of this query (the collectives), you could add color to your graph. You can do that by adding a bit of extra code in your query.

First you want to “bind” a web color value to a variable. You need to add: “BIND('ffff00' as ?rgb)” inside your query code, below the line specifying the collective variable, like so:

#defaultView:Graph
SELECT ?collective ?collectiveLabel ?member ?memberLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7.
  BIND('ffff00' as ?rgb)
  OPTIONAL { ?collective rt:P43 ?member. }
}
LIMIT 100


But if you run the query now, you will see that no color effect has taken place yet.

To display the new color variable, you also need specify it inside your SELECT clause, like so:

#defaultView:Graph
SELECT ?collective ?collectiveLabel ?rgb ?member ?memberLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7.
  BIND('ffff00' as ?rgb)
  OPTIONAL { ?collective rt:P43 ?member. }
}
LIMIT 100


If you run the query now, you will see that the bubbles representing collectives have been colored and stand out much more easily.

A screenshot of the query results shown in a graph visualization with colored nodes

Add artworks and artwork images

To make your results more interesting you might want to add further attributes to the query results, such as which artworks by these collectives are available in the ArtBase. You can do that by simply picking the relevant property (“artwork”) from the “Show” button in the query helper (try that after Step 6 above). Or you could add the following statement to your query: “?collective rt:P60 ?artwork”. This specifies that you are looking for the collectives represented within the variable ?collective, which have the property P60 (“artwork”) listed on their records, and the corresponding values would be represented through the variable ?artwork.

You will notice that adding an attribute via the “Show” button in the query makes that attribute OPTIONAL:

SELECT ?collective ?collectiveLabel ?member ?memberLabel ?artwork ?artworkLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7.
  OPTIONAL { ?collective rt:P43 ?member. }
  OPTIONAL { ?collective rt:P60 ?artwork. }
}
LIMIT 100


For this step in the manual editing process, you may want to remove the optional clause and simply type the statement as specified above.

SELECT ?collective ?collectiveLabel ?member ?memberLabel ?artwork ?artworkLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7.
  OPTIONAL { ?collective rt:P43 ?member. }
  ?collective rt:P60 ?artwork.
}
LIMIT 100


If you run the query now, you will notice that you are already seeing 100 results. This means we are reaching the limit set by the query helper by default and we may need to increase the limit or remove it entirely. You can do so by simply editing the limit number in the code editing area, or deleting the whole line: “LIMIT 100”. You can also edit limit numbers from the query helper interface by clicking on the “Limit” button below the “Show” button and editing the number of emptying any limit with the bin icon.

Without any limit the query shows 165 results (at least at the time of writing).

As a next step in manually editing attributes, you may want to select attributes of the attributes, in short – data that relates to the artworks, and not the collectives directly. This level of relational querying can be easily done with SPARQL, but the query helper interface is not yet advanced enough to offer this option within the Filter / Show area. To get results for images of the artworks connected to the collectives in our example, you need to add the following statement to your query code: “?artwork rt:P126 ?image.” And don’t forget to add the image variable in your SELECT clause at the top of the query.

SELECT ?collective ?collectiveLabel ?member ?memberLabel ?artwork ?artworkLabel ?image WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7.
  OPTIONAL { ?collective rt:P43 ?member. }
  ?collective rt:P60 ?artwork.
  ?artwork rt:P126 ?image.
}


Note that to get a hint regarding property numbers (e.g. a hint that P126 is the property “image”), you can use an auto-suggest feature within the code editing area by pressing CTRL+space after you type the prefix for properties, which in Rhizome’s Wikibase is “rt:”.

If you run the query now you should have even more results displayed in your table, which can then be visualized as an Image Grid or Graph. You can further experiment with adding or removing attributes from your query manually or with some help from the query helper.

Count and filter by number of artworks

Finally, a useful aspect of being able to manually edit the SPARQL code is the possibility to add filters for quantity, for example only listing collectives with a certain number of members, or only listing collectives with a certain number of artworks.

This is a fairly advanced degree of working with SPARQL, so if you want to get more detail beyond what is provided in this short tutorial, refer to the Query page, where you will see links to more extensive external tutorial materials.

To work with COUNT and GROUP functions, first you will need a nested query within the main query:

SELECT ?collective ?collectiveLabel ?artwork ?artworkLabel ?count WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7;
    rt:P60 ?artwork.
  {
    SELECT ?collective ?collectiveLabel (COUNT(?artwork) AS ?count) WHERE {
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      ?collective rt:P3 r:Q7;
        rt:P60 ?artwork.
    }
    GROUP BY ?collective ?collectiveLabel
    ORDER BY DESC (?count)
  }
}
ORDER BY DESC (?count)


Once again, don’t forget to add your ?count variable within your SELECT clause at the top of the query. Running this query will result in an ordered list in descending order (which is specified by the final ORDER BY DESC fruition in the end of the query).

A screenshot of the query results shown in a table, sorted by artwork counts

Note that because we are still displaying all individual artwork names, the rows for each collective are repeated as many times as the number of artworks.

If you want to only see a count of all artworks and no artwork titles, you need to delete the ?artwork and ?artworkLabel variables from the SELECT clause at the top of the query, and add DISTINCT infront of the ?collective variable, like so:

SELECT DISTINCT ?collective ?collectiveLabel ?count WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7;
    rt:P60 ?artwork.
  {
    SELECT ?collective ?collectiveLabel (COUNT(?artwork) AS ?count) WHERE {
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      ?collective rt:P3 r:Q7;
        rt:P60 ?artwork.
    }
    GROUP BY ?collective ?collectiveLabel
    ORDER BY DESC (?count)
  }
}
ORDER BY DESC (?count)


Finally, if you want to filter by a specific count, e.g. filter for collectives with more than two artworks in the ArtBase, you can use a FILTER clause, like so:

SELECT DISTINCT ?collective ?collectiveLabel ?count WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?collective rt:P3 r:Q7;
    rt:P60 ?artwork.
  {
    SELECT ?collective ?collectiveLabel (COUNT(?artwork) AS ?count) WHERE {
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      ?collective rt:P3 r:Q7;
        rt:P60 ?artwork.
    }
    GROUP BY ?collective ?collectiveLabel
    ORDER BY DESC (?count)
  }
  FILTER (?count>2)
}
ORDER BY DESC (?count)


Lastly, try experimenting with different modes of visualizing this quantitative data. For example, a bubble chart visualization is an effective way to display differences in quantity.

A screenshot of the query results shown as a bubble chart visualization

To explore additional, more complex, ways for manually editing your SPARQL query, refer to the more extensive external tutorial materials listed on the Query page.