The latest instance of the course can be found at:
Semantic Web: 2023 MOOC
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. Yasgui is a useful tool for writing SPARQL queries.
It is recommended that you try your queries first using Yasgui before submitting them.
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
and there is also a web portal that provides several web user interfaces
to different WarSampo datasets.
A+ presents the exercise submission form here.
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.
Answer the following questions based on the results of above DESCRIBE query.
Give the URI reference of Winter War’s time span in WarSampo.
Write the URI as it is, e.g. http://my-uri.net/subdomain.
Give the Finnish labels for Winter War’s class (determined by rdf:type)
and what the Winter War falls within in WarSampo.
Return the two labels separated by a
space e.g. "label one"@fi "label two"@fi.
"label one"@fi "label two"@fi
Hint: this information is found most easily by expanding the DESCRIBE query with
whatever is linked to the Winter War resource.
In the following exercises, DESCRIBE queries can be useful to inspect
how a resource is described.
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.
?sub http://www.cidoc-crm.org/cidoc-crm/P138_represents ?obj
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 isn’t 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.
The following SPARQL queries have several errors. Fix the queries so that they work.
For each query submit the result the fixed query provides.
You must also SUBMIT the fixed QUERIES. You can submit the queries as a single file after answering
the query specific questions.
If you don’t submit the queries, any points given by correct query results might be removed.
In this section we make use of aggregates. SPARQL aggregates work similary to SQL aggregates. Here are the available
SPARQL Aggregates and a few examples:
Hint: You might have noticed it already, but the editor in YASGUI tries to help you!
If it detects a syntax error, the erroneus line lights up red and hovering your mouse over
the exclamation mark on the left side on the row shows you feedback on the error.
The following query tries to retrieve the MRR-number (Mannerheim-ristin ritarit, Mannerheim Cross) of C.G.E. Mannerheim.
PREFIX : <http://ldf.fi/schema/warsa/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
?person <http://ldf.fi/schema/warsa/actors/knight> mrr ;
skos:prefLabel ?label .
FILTER (?label != "Carl Gustaf Emil Mannerheim")
This query tries to count how many events C.G.E. Mannerheim has participated in
in the WarSampo dataset.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
SELECT (COUNT (DISTINCT ?event) as ?event_count)
?event crm:P11_had_participant ?person .
?person skos:prefLabel ?name_label .
FILTER SELECT(?label = "Carl Gustaf Emil Mannerheim")
Now, submit the fixed queries.
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.
Note: The automated tests might not work properly when using
FILTER works well
as an alternative. Also, grouping by photo count breaks the tests.
On the GROUP BY line avoid the syntax “GROUP BY(?variable)” as the
automatic tests don’t work with that syntax. Use instead syntax without
parentheses like this “GROUP BY ?variable”.
Grouping by aggregated variable (like photo count here) will break the tests
in later assignments as well.
Using YASGUI and the SPARQL endpoint of DBpedia (https://dbpedia.org/sparql),
visualize how many people described in DBpedia have been born (dbo:birthPlace)
in each Finnish city or town. Finnish cities and towns have a dct:subject
relation to dbc:Cities_and_towns_in_Finland. Create a pie chart visualization,
which can be found in YASGUI by clicking Chart → Configure → Charts → Pie → Select your preferred pie chart.
Include only the 20 cities with the largest amount of known people born in them, and
use the English labels for cities.
YASGUI should automatically define the prefixes dct and dbc when you write them,
or you can manually define them with:
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dct: <http://purl.org/dc/terms/>
Find the city which has the 4th highest birth count in Finland according to DBpedia.
Submit city name e.g. Espoo
Give the percentage for people born in Tampere of the birth counts given
by the above query. (The generated pie chart gives the percentages per city)
Submit the percentage with one decimal precision e.g. 0.0%
Give us optional feedback on the assignments to help us improve the course.
Open feedback, tell us anything.