I’ve had a decent understand of what the VALUES keyword can do for a while (see SPARQL 1.1’s new VALUES keyword and “Creating Tables of Values in your Queries” in my book Learning SPARQL) but lately I’ve gained a greater appreciation of ways to use it. For example, last month I used it to map codes assigned by an entity recognition tool to schema.org classes. This month I found a nice way to use it to control one of Wikidata’s many cool data visualization possibilities. By sending the Wikidata query service some data in a VALUES clause in my query, I don’t have to rely completely on what’s in Wikidata to drive the visualization.

Wikidata’s timeline visualization lets you view a chart of events displayed in the order in which they happened–for instance, the launch date of space probes, which Wikidata’s sample timeline query asks for. Requesting two dates in your query result adds bars to the display to visually show the elapsed time between those dates.

As their demonstration shows, this is pretty simple if you can come up with a query for the things you want displayed on the chart. But what if the entities you want to see there don’t have anything in common that you can query for?

In my case, I wanted to create a timeline of Shakespeare and certain famous people who lived in his time. I wanted to see two composers, two scientists, and the “statesman” Walter Raleigh, but I knew of no single query that would return these six people. (I read books on music and science that mention one or the other so I thought it would be nice to see just how contemporary they were.)

The VALUES query made it easy. I used Wikipedia and Wikidata to find the identifier for each person (for example, for one of them, I clicked Wikidata item on Palestrina’s Wikipedia page and saw from its URL that his identifier is Q179277) and added them to the VALUES list with a wd: prefix. The comment at the top of the query tells Wikidata that I want to see the Timeline visualization:

SELECT ?name ?dateOfBirth ?dateOfDeath 
  VALUES ?person { wd:Q692 wd:Q179277 wd:Q53068 wd:Q307 
                   wd:Q9191 wd:Q189144 }
  ?person wdt:P569 ?dateOfBirth ;
          rdfs:label ?name ; 
          wdt:P570 ?dateOfDeath .
  FILTER ( lang(?name) = "en" )

You can try it out yourself. Here is the result:

Timeline of Shakespeare contemporaries

As I showed in last month’s blog entry, a VALUES clause can hold two-dimensional sets of data in addition to simple lists like my query about Shakespeare’s contemporaries. This enables even more possibilities when using your own data with Wikidata’s wide choice of visualization tools.

Comments? Reply to my tweet (or even better, my Mastodon message) announcing this blog entry.