Visualizations
Learn more about the different types of visualisations that the Wikibase Query Service is offering. Following the Wikidata-documentation, we give an overview, specifying which types of datatypes and sometimes additional data is needed in order to display the MiMoText data.
Overview
The Wikidata Query Service offers various options for visualising the result of queries.
There are two ways to choose a visualisation, either via the “eye” icon that will appear when you run a query or via the “default view” keyword within a query as follows: #defaultView:[chosen view]
.
Table
Description |
---|
|
Needed |
|
Example in the MiMoTextBase |
|
Explanation of the query
Define all prefixes needed for the query:
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
Within SELECT
we ask for unique objects by calling DISTINCT
. To retrieve the datatype of the object ?o
, call datatype
of the object and bind it to a new variable ?datatype
. Also select the item ?o
, the object label ?oLabel
and the properties ?p
SELECT DISTINCT (datatype(?o) as ?datatype) ?o ?oLabel ?p
In WHERE
, ask for a specific entity as subject mmd:Q1053
and all properties ?p
and connected values ?o
. By using the Wikibase Label Service
, you can retrieve the labels.
To sort the result in descending oder of ?datatype
, use ORDER BY
.
WHERE{
mmd:Q1053 ?p ?o.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY desc(?datatype)
Image Grid
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
Define the default view #defaultView:ImageGrid
and the prefixes for the MiMoTextBase and for Wikidata.
#defaultView:ImageGrid
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
Select the author item ?author
, the labels ?authorLabel
and the corresponding images ?img
.
SELECT ?author ?authorLabel ?img
In WHERE
, define authors by items that have occupation mmdt:P11
author mmd:Q11
. By adding mmdt:P13 ?wikiLink
, restrict the query to those authors that have an exact match (P13) to Wikidata and get the Wikidata links. Using the Wikidata link within SERVICE <https://query.wikidata.org/sparql>{...}
, we now have access to all the statements within Wikidata. Keep in mind to use the defined Wikidata prefixes. Via wdt:P18
you can now retrieve the images for the authors, where available.
WHERE {
?author mmdt:P11 mmd:Q11;
mmdt:P13 ?wikiLink.
SERVICE <https://query.wikidata.org/sparql>{
?wikiLink wdt:P18 ?img.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Adding options
Hiding the image file name:
By adding #defaultView:ImageGrid{"hide":["?img"]}
the link to the image source can be hidden, see.
Map
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
First, define the #defaultView:Map
and the neccessary PREFIXES
for the MiMoTextBase and Wikidata as you need these for the coordinates.
#defaultView:Map
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
Within SELECT
, you can select the desired variables, but for a map visualisation you need coordinates.
In the WHERE
clause we now choose all ?items
that have a place of publication mmdt:P10
. These in turn have a match to Wikidata ?loc mmdt:P13 ?WikiDataEntity
. Using a federated query we now can retrieve the coordinates of those publication places.
SELECT DISTINCT ?item ?itemLabel ?locLabel ?WikiDataEntity ?coordinateLocation
WHERE { ?item mmdt:P10 ?loc.
?loc mmdt:P13 ?WikiDataEntity.
#Federated Query -> Wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiDataEntity wdt:P625 ?coordinateLocation
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
Adding options
If you want to add a layer to your map, you can choose another variable, e.g. the tone of the novels via ?item mmdt:P38 ?tone
in the WHERE
clause. Take the labels of the ?tone
variable and bind them to the variable ?layer
in SELECT
. On the map you now get different colors for the different tones.
You also can create layers on your own by binding variables to categories. As you need a variable ?layer
within SELECT
, you can use BIND
to assign layer variables. See here an example for creating an individual layer based on a variable, e.g. token count (be careful: layers can overlap, so you don’t see all of them immediately) and marker clusters.
Same example with hidden coordinates.
Line Chart
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
As there are multiple functions provided, we can make use of them to get the average count of numbers, in this example the token count by calling (avg(?tokencount) as ?avgtokencount)
. As we use this function, we have to GROUP BY
all variables called in SELECT
, except the one we use to calculate the average (see line 14).
For extracting the year, without showing the day and month (as these are all set to 1st of January by default in data type DateTime only having a specific year), see line 10, where we extract the year via YEAR(?publicationdate)
, turn it into a string variable str(YEAR(...))
and assign it to a new variable name by BIND(str(...))
.
#defaultView:LineChart
#title:average token count for each possible narrative form per year
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?year (avg(?tokencount) as ?avgtokencount) ?narrForm ?narrFormLabel
WHERE{
?item mmdt:P9 ?publicationdate. # get publication date
?item mmdt:P40 ?tokencount. # get tokencount
BIND(str(YEAR(?publicationdate)) as ?year). # extract year from pubdate
?item mmdt:P33 ?narrForm. # get narrative form
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
GROUP BY ?narrForm ?year ?narrFormLabel
ORDER BY ?year
Bar Chart
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
See line charts.
Adding options
For creating an animated bar chart, let’s take another query: Count of different tones per intention and year as animated bar chart, see here
For an animated chart we need four variables, in this case the intention, the count of the variable for the tone, the labels of the tone and the publication dates. The last one will be the variable the animation switches between. As we call the COUNT(...)
, we also need to GROUP BY
all other variables occurring in SELECT
.
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
# (animated)
# Show the tone count per intention and year
#defaultView:BarChart
SELECT ?intentionLabel (COUNT(?tone) AS ?toneCount) ?toneLabel ?year
WHERE{
?item mmdt:P2 mmd:Q2; # item is instance of literary work
mmdt:P9 ?pubdate; # get the publication date
mmdt:P38 ?tone; # get tone of work-item
mmdt:P39 ?intention. # get intention of work-item
?tone rdfs:label ?toneLabel. # get the tonality-label
?intention rdfs:label ?intentionLabel. # get the intentionality-label
FILTER(LANG(?toneLabel) = "en"). # filter for language
FILTER(LANG(?intentionLabel)="en"). # filter for language
BIND(str(YEAR(?pubdate)) as ?year). # filter year of the publication date
}
GROUP BY ?year ?toneLabel ?intentionLabel
Scatter Chart
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
See line chart.
Area Chart
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
As we want to visualise the count of occurrences of publication places, we need to use the COUNT
function for counting the publication places variable. Therefore we need to use the GROUP BY
on all other variables within SELECT
. Next, as we want to limit the occurrences to be at least 4, we can use HAVING (count(?pubPlaceLabel) > 4)
. Another option would be to reuse the newly generated ?count variable via HAVING (?count > 4)
#defaultView:AreaChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?date (count(?pubPlace) as ?count) ?pubPlaceLabel
WHERE{
?item mmdt:P2 mmd:Q2;
mmdt:P9 ?date;
mmdt:P10 ?pubPlace.
?pubPlace rdfs:label ?pubPlaceLabel.
FILTER(LANG(?pubPlaceLabel) = "en").
}
GROUP BY ?date ?pubPlaceLabel
HAVING (count(?pubPlaceLabel) > 4)
# other option:
# HAVING (?count > 4)
Bubble Chart
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
To generate a bubble chart, you need to use the count
function to get the count of a desired variable, as the size of the bubbles represent the number of occurrences of that variable. This also means that you have to GROUP BY
all the other variables used in SELECT
, in this case it only concerns the ?topicLabel
. To put the largest bubbles in the center of the visualisation, you can add ORDER BY DESC([count-variable])
.
#defaultView:BubbleChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?topicLabel (COUNT(?topicLabel) as ?count)
WHERE {
?item mmdt:P2 mmd:Q2. # get all instances of literary work
?item mmdt:P36 ?topic . # get the thematic concepts of the items
?topic rdfs:label ?topicLabel .
FILTER(LANG(?topicLabel) = "en") .
}
GROUP BY ?topicLabel
ORDER BY desc(?count)
TreeMap
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
In order to retrieve a tree map you must consider the order of the variables within SELECT
as it will reflect the hierarchy of the tree. As we chose theme
as the first variable, all following variables will be clustered within the corresponding theme.
Tree
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
To create an expandable tree, we must select more than one variable. Within SELECT
the order of the variables will represent the hierarchy of the tree. Also each of the variables must be written on a separate line (except the associated label variables).
SELECT ?author ?authorLabel
?item ?itemLabel
?topic ?topicLabel
SELECT
will therefore create a tree with the authors as nodes. When expanded, the novels of each author and the thematic concepts of each novel will appear.
Timeline
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
We query for the awards the authors of the MiMoTextBase have received and the dates they were awared and visualise the result as a timeline. Since we do not have this information in the MiMoTextBase, we formulate a federated query to retrieve Wikidata.
Therefore we first retrieve all possible Wikidata matches via ?item mmdt:P13 ?Wikilink
. Now calling the SERVICE <https://query.wikidata.org/sparql>
we can query statements within Wikidata.
If you have a look at the property award received
e.g. of this item, you can see that the value award received
(P166) has the item Fellow of the Royal Society. This item itself has a so called qualifier
point in time
for the value 26 February 1730. This is the data that we want to receive.
In order to get all statements and qualifiers associated to a property, we first need to define new PREFIXES
:
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
Now, within in the Wikidata query, we first retrieve all values associated with P166
(award received
) via
?WikiLink p:P166 ?awardProperty.
As we also want the label of the awards, we need to get the statements and the labels.
?awardProperty ps:P166 ?award. # get the statement of the propery
?award rdfs:label ?awardLabel. # get the Label
FILTER(LANG(?awardLabel) ="en").
Not all of the statements have the qualifier point in time
, so we use OPTIONAL
to get all statements and, where available, a point in time
.
OPTIONAL{?awardProperty pq:P585 ?time.} # get the qualifier 'point in time' where available
Dimensions
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
Since the variables within SELECT
are represented as dimension axes, the order will also be represented.
Graph
Description | |
---|---|
|
|
Needed | |
|
|
Options | |
|
|
Example in the MiMoTextBase | |
|
|
|
Explanation of the query
With this query we want to get all organisations of which the authors in the MiMoTextBase were members. This is an information we don’t find in the MiMoTextBase, therefore we use a federated query to retrieve Wikidata. Asking for item mmdt:P13 ?WikiLink
we get the Wikidata matches of the authors. Using this variable, we can now call SERVICE
https://query.wikidata.org/sparql to query Wikidata. Via ?WikiLink wdt:P463 ?memberOf
we get all organisations connected to the authors. In the graph, edges occur between the authors and their associated organisations.
Adding options
We can add the condition that only authors of organisations with at least 2 members are shown and retrieve the images of the authors where available, see here.
To limit the result to those organisations that have at least two members from the MiMoTextBase, we can expand the query above by a second query within the first as nested query. After the first query, but before closing it, we are going to copy the same query with the exception of adding COUNT(?author)
to SELECT
. Therefore we need to add the GROUP BY
to the end of the query. Via HAVING ([count-variable] > 1)
we now can filter for those organisations having at least two members.