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
  • default view
  • every data type possible
  • every variable in SELECT is displayed in a table as column
Needed
  • variables (e.g. ?item) in SELECT clause
Example in the MiMoTextBase
  • show all datatypes of the objects under item Q1053 (“Les liaisons dangereuses”) and the connecting predicates. This query will result in the following visualization:

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
  • shows image results in a grid
Needed
  • exact match (P13) for a federated query to Wikidata (as we don’t have images in our graph)
  • image files in Wikidata for item
Options
  • hide variables
Example in the MiMoTextBase
  • show all authors in the MiMoTextBase having an exact match with Wikidata and an image, see query here

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
  • shows result in a map as map markers
Needed
  • location item (e.g. place of publication (P10)) having an exact match (P13) with Wikidata where location coordinates are available (P625)
Options
  • possible variables: ?layer: shows layers of specific properties
  • markercluster (boolean or object, for more information see)
  • hide
Example in the MiMoTextBase
  • query for all publication places, their Wikidata match and geographic coordinates, see query here.

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
  • shows result as a line graph
  • first variable will be mapped on x-axis, second on y-axis
Needed
  • at least 2 variables of the data types numbers, labels or datetime
Options
  • stacked: 3 variables needed; third variable (category or label) for displaying the categories
  • animated line chart: 4 variables needed, first is on x-axis, second on y-axis, third (category or label) for displaying the categories and fourth (category or label) for animation; for an example of an animated graph, take a look in the bar chart section
Example in the MiMoTextBase
  • get the average token count for each possible narrative form per year, see query here

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
  • shows result as a bar chart
  • first variable will be mapped on x-axis, second on y-axis
Needed
  • at least 2 variables of datatypes numbers, labels or datetimes
Options
  • stacked: 3 variables needed; third variable (category or label) for displaying the categories
  • animated bar chart: 4 variables needed, first is on x-axis, second on y-axis, third (category or label) for displaying the categories and fourth (category or label) for animation
Example in the MiMoTextBase
  • get the average token count for each possible narrative form per year, for query see here

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
  • shows result as a scatter chart
  • first variable will be mapped on x-axis, second on y-axis
Needed
  • at least 2 variables of datatypes numbers, labels or datetimes
Options
  • stacked: 3 variables needed; third variable (category or label) for displaying the categories
  • animated scatter chart: 4 variables needed, first is on x-axis, second on y-axis, third (category or label) for displaying the categories and fourth (category or label) for animation; for an example of an animated graph, take a look in the bar chart section
Example in the MiMoTextBase
  • get the average token count for each possible narrative form per year, see query here

Explanation of the query

See line chart.

Area Chart

Description
  • shows result as an area chart
  • first variable will be mapped on x-axis, second on y-axis
Needed
  • at least 2 variables of datatypes numbers, labels or datetimes
Options
  • stacked: 3 variables needed; third variable (category or label) for displaying the categories
  • animated area chart: 4 variables needed, first is on x-axis, second on y-axis, third (category or label) for displaying the categories and fourth (category or label) for animation; for an example of an animated graph, have a look in the bar chart section
Example in the MiMoTextBase
  • Show publication places that occurr at least 5 times per year, see here

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
  • shows result as a bubble chart
  • size of bubble represents count of variable
Needed
  • variables of the possible datatypes label, item, quantity
  • `(count(?variable) as ?count)` to count a variable within SELECT
  • GROUP BY all other variables that are in SELECT
Options
Example in the MiMoTextBase
  • Show the thematic concepts per novel, see query here

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
  • shows result as tree map
  • order of variables in SELECT will be reflected by levels of the tree map
Needed
  • variables of the possible data types label, item or quantity
Options
Example in the MiMoTextBase
  • Thematic concepts linked to the narrative location "rural area", see query here

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
  • shows result as an expandable tree
Needed
  • variables of the possible data types label, item or number
  • special order of variables in different lines (see example): the first will be the node of the tree, the others follow as branches or leaves
Options
  • for using common media: exact match (P13) needed
Example in the MiMoTextBase
  • Get all authors, their novels and the respective thematic concepts, for query see here

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
  • shows result as a timeline
Needed
  • one variable of data type label, item or number
  • one variable of data type datetime
Options
  • hide: as dates are of type `point in time`, there will be a default day and month in the MiMoTextBase (1. January). Using the option hide shows the year only.
Example in the MiMoTextBase
  • Visualise the points in time when authors of the MiMoTextBase received an award, see query here. Please note: If you switch to table view, you get more results. But as there is no point in time statement available, it is not shown in the timeline.

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
  • shows variables as parallel axes with the possible values and draws connections between them if they exist
  • possible data types are label, numbers and datetime
Needed
  • at least two variables to show their connection
Options
  • for use of common media: exact match (P13) needed
Example in the MiMoTextBase
  • Get the dimension between token count and narrative form, see query here

Explanation of the query

Since the variables within SELECTare represented as dimension axes, the order will also be represented.

Graph

Description
  • shows result as an interactive graph
Needed
  • one variable of type item as node
Options
  • possible additional data types: label for showing the item name
  • image for node item if item has exact match (P13) with Wikidata and there is an image available
  • node size when data type number is given
Example in the MiMoTextBase
  • Show a graph of the authors within the MiMoTextBase connected with the organisations they were members of. You can zoom in to view the labels:

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.

Previous Next