The latest instance of the course can be found at: Semantic Web: 2024 MOOC
- CS-E4410
- 3. SPARQL query language and protocol
- 3.2 SPARQL basics
SPARQL basics¶
YASGUI application¶
YASGUI is an application for easily using SPARQL endpoints, it can be accessed at http://yasgui.org/
Get acquainted with the tool and submit the example query to DBpedia.
Note: The first exercise requires the usage of developer tools in your web browser, e.g. integrated DevTools in Firefox or Chrome (can be opened by pressing F12-key (Linux/Windows) or right-clicking the page and selecting “Inspect element” or “Inspect”).
SPARQL ASK¶
SPARQL ASK can be used to test if a certain query pattern exists or not.
WarSampo (Sotasampo in Finnish) contains large amounts of information about World War 2 in Finland. The data is published on a SPARQL endpoint at http://ldf.fi/warsa/sparql, and there is also a web portal that provides several web user interfaces to different WarSampo datasets.
A+ presents the exercise submission form here.
SPARQL DESCRIBE¶
Query the WarSampo endpoint for the description of the resource with the English label “Winter War” using SPARQL DESCRIBE. Expand the DESCRIBE query to also return descriptions of all resources to which there is a link from (any predicate connecting to) the Winter War resource.
In the following exercises, DESCRIBE queries can be useful to inspect how a resource is described.
Simple SPARQL SELECT¶
Using the WarSampo SPARQL endpoint, create a query that returns the URIs of 10 photographs (class http://ldf.fi/schema/warsa/Photograph), from which there is a direct relation to C.G.E. Mannerheim, the commander-in-chief of Finland’s armed forces (skos:prefLabel “Carl Gustaf Emil Mannerheim”).
The relation (property http://www.cidoc-crm.org/cidoc-crm/P138_represents) indicates that the person is automatically recognized as a named entity in the photograph’s metadata description. This usually means that the person is in the photograph, or somehow else involved in the photography event.
For instance, ?sub http://www.cidoc-crm.org/cidoc-crm/P138_represents ?obj
inside a SPARQL WHERE clause to WarSampo endpoint would retrieve all triples that describe named
entities being in a photograph’s description.
Remember to test your query in YASGUI before submitting your answer.
Also remember to limit your query to 10 results with SPARQL LIMIT clause. Besides helping you get the tests correct, it will make testing your queries in YASGUI much faster if the result set is large.
Note: The tests don’t access all WarSampo data, thus you might get empty results from tests even though YASGUI returns some results or even the correct ones. This means there is something likely irrelevant in the query.
A+ presents the exercise submission form here.
SPARQL Aggregates¶
Modify the query from the previous exercise to show who are represented (property http://www.cidoc-crm.org/cidoc-crm/P138_represents) in the same photographs as C.G.E. Mannerheim. Create a query that will return the names of the 10 people who are most often represented in the same photographs as Mannerheim, along with the number of photographs the person is represented in with Mannerheim.
Hint: SPARQL aggregates work similary to SQL aggregates. Here are the available SPARQL Aggregates and a few examples: https://en.wikibooks.org/wiki/SPARQL/Aggregate_functions.
Note: The automated tests might not work properly when using HAVING operator. FILTER works well as an alternative. Also, grouping by photo count breaks the tests.
A+ presents the exercise submission form here.