Workshop #3
Introduction to Wikidata Query Service
REFRESHER
Workshops #1 & #2
Workshop #3
REFRESHER
Workshop #1 Introduction to Wikidata
A triple (also called statement in Wikidata) is the basic unit of a knowledge base.
A triple consists of:
Element
Example:
Property
Value
was composed by
Tchaikovsky
The Nutcracker
Introduction to Wikidata Query Service
Workshop #3
REFRESHER
Workshop#2 Contributing to Wikidata
Introduction to Wikidata Query Service
Workshop #3
Workshop Scope
Workshop #1: Exploring Wikidata
Workshop #2: Creating a Wikidata item (André Laliberté)
Workshop #3 : How do you use Wikidata? With SparQL queries.
The best ways to use data is by searching and extracting it with SparQL. It’s the tool you use to check that the data you added to Wikidata is producing the results you want.
You don’t need to know everything about SparQL syntax to add data to Wikidata. However, it can help you understand how others use data and help you see your data input from different points of view.
Introduction to Wikidata Query Service
Workshop #3
Introduction to SparQL
Content
Part 1
Part 2
Part 3
End of workshop
Introduction to Wikidata Query Service
Workshop #3
Part 1
Search and History in Wikidata
Workshop #3
Searching for Wikidata Entities
Before creating a new item (an entity), make sure you are not creating a duplicate.
There are several ways to search:
Introduction to Wikidata Query Service
Workshop #3 Part 1
Searching in Wikidata: Header Field
Begin the search in the header field of the Wikidata page.
A menu appears when you type in this field. Pay attention to the last menu item, the one that will take you to a search page.
Notice how important a good description is in guiding your choice when items have the same label.
Introduction to Wikidata Query Service
Workshop #3 Part 1
Searching in Wikidata: Results Page
This page displays the results of a search.
Each result has three lines of data:
Use property and item filters to refine a search.
Introduction to Wikidata Query Service
Workshop #3 Part 1
History of Page Revisions
Every page in a Wiki has a history. In Wikidata, every item has a history page.
A page’s history lets you see who made a revision, when it was done, and the scope of the revision in bytes.
It is also possible to compare different versions.
Introduction to Wikidata Query Service
Workshop #3 Part 1
End of Part 1
Search for the Stars!
Workshop #3
Part 2
SparQL Query Syntax
Workshop #3
SparQL Language
Queries are text-based and follow SparQL syntax.
URL of Wikidata query editor: https://query.wikidata.org/
SparQL language is highly structured and admittedly complex and a bit off-putting. But it is VERY powerful. You can create a SparQL query without having to memorize anything.
To learn how to use SparQL, I recommend this tutorial:�https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial
Introduction to Wikidata Query Service
Workshop #3 Part 2
A SparQL Query from an example
I recommend that you always start with an example (on button bar).
That way, you don't need to write your request from scratch!
Introduction to Wikidata Query Service
Workshop #3 Part 2
A SparQL Query
Variable
Comment
Service is for label names�Here, the choice of interface language, in French and if there are no results, in English as the default choice
Introduction to Wikidata Query Service
Workshop #3 Part 2
Editor of the Wikidata Query Service
You don't need to remember the identifiers of your elements. You can use the auto-completion feature.
To do so, type the name of the element or property after the namespace identifier (“wd:” for elements or “wdt:” for properties), then press on the keyboard keys [Control-Space].
Introduction to Wikidata Query Service
Workshop #3 Part 2
SparQL Language: Basic Syntax
SELECT: list of variables you want returned
WHERE: search criteria used to restrict
SERVICE: supplemental tools
GROUP BY: group the results according to one or several variables
ORDER BY: sort order of the results
Introduction to Wikidata Query Service
Workshop #3 Part 2
SparQL Language: Comments
Comments are preceded by a # (hash mark)
Some comments can change the display of results
Example: #defaultView:Map to display the results as geographic coordinates on a map
Introduction to Wikidata Query Service
Workshop #3 Part 2
SparQL Language: Variables
Variables are key to extracting data.
Introduction to Wikidata Query Service
Workshop #3 Part 2
SparQL Language: Searching with Triples
In this example, we are searching for all items whose value, for the property "instance of (P31)" is "house cat (Q146)".
Since the variable is in the position of the main element (the subject), this request will extract all the elements in triplets where the property and the value are present.
Introduction to Wikidata Query Service
Workshop #3 Part 2
End of Part 2
Workshop #3
Part 3
Viewing Query Results in WDQS
Workshop #3
Subclasses of "performing artist"
SELECT ?vClass ?vLabel
WHERE
{
?vClass wdt:P279* wd:Q713200 .
OPTIONAL {
?vClass rdfs:label ?vLabel
FILTER (LANG(?vLabel) = "en") .
}
}
?vClass = variable containing all the classes that qualify
?vLabel = variable containing the name of the class of the variable ?vClass
P279 = subclass of
Q713200 = performing artist
Note the period.
Introduction to Wikidata Query Service
Workshop #3 Part 3
Subclasses of "performing artist"
Here is the result of the query.
The columns are the variables from the SELECT section.
In the results header, you can see « 185 results in 319 ms ».
You can download a file containing the results to your computer.
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS : Bubble Chart Query
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS : BubbleChart Query (cont.)
?vOccup wdt:P279 wd:Q713200
[occupations] subclass of performing artist
?vArtist wdt:P106* ?vOccup
[artists] occupation [occupations]
?vArtist wdt:P27 wd:Q16 �[artists] country of citizenship Canada
Variable containing occupations
Variable containing performing artists
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS : BubbleChart Query (cont.)
wdt:P279�subclass of
wd:Q713200�performing artist
wdt:P106*�occupation
?vOccup�[occupations]
wdt:P27�country of citizenship
wd:Q16�Canada
?vArtist�[artists]
?vOccup�[occupations]
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS: Viewing Results as a Bubble Chart
To display results as a Bubble chart, you need at least two columns of data.
A column with text or entities and a column with numeric values. Each entity is represented as a bubble, and the number sets the size of the bubble.
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS: Map View Query
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS: Map View Query (cont.)
?vTheatre wdt:P31* wd:Q24354
[theatres] instance of item theatre (building)
?vTheatre wdt:P625 ?vCoord
[theatres] geographic coordinates [geo. coordinates]
?vTheatre wdt:P17 wd:Q16
[theatres] country Canada
Variable containing geographic coordinates
Variable containing theatres
Introduction to Wikidata Query Service
Workshop #3 Part 3
WDQS: Viewing Results on a Map
Introduction to Wikidata Query Service
Workshop #3 Part 3
End of Part 3
Workshop #3
Recap
What you need to know
Workshop #3
Part 1 : Things to Remember
Introduction to Wikidata Query Service
Workshop #3
Part 2: Things to Remember
Introduction to Wikidata Query Service
Workshop #3
Part 3: Things to Remember
Introduction to Wikidata Query Service
Workshop #3
Acknowledgments
Main Project Partners
Financial partners
Introduction to Wikidata Query Service
Workshop #3
End of Workshop
Keep on searching!
Workshop #3
Nom de la diapositive
Introduction to Wikidata Query Service
Workshop #3