Download presentation
Presentation is loading. Please wait.
Published byYolanda Cruz Lara Modified over 6 years ago
1
Logics for Data and Knowledge Representation
SPARQL -- Exercises Feroz Farazi 1
2
Exercise 1 Suppose that an RDF model represents information about real world entities of unknown types. The entities can be persons, locations, books, monuments, organizations, etc. Write a SPARQL query to return all possible information about all kinds of entities. Write a SPARQL query that can return at most 5 triples representing information
3
Solution 1 SELECT ?x ?y ?z WHERE { ?x ?y ?z } SELECT ?x ?y ?z WHERE
(ii) SELECT ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 5 You can try the queries here:
4
Exercise 2 Given that an RDF model represents information about books and the model is created using standard vocabularies. Write a SPARQL query that can return the authors of the books. Note that books can be represented as URIs. Write a SPARQL query that can return the authors of the books. Note that books must be represented as literals if available otherwise as URIs. Write a SPARQL query that can return the date of publication of the books.
5
Solution 2 (i) PREFIX dc: < SELECT ?book ?author WHERE { ?book dc:creator ?author } (ii) PREFIX dc: < SELECT ?bookTitle ?author WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle }
6
Solution 2 PREFIX dc: <http://purl.org/dc/elements/1.1/>
(iii) PREFIX dc: < SELECT ?bookTitle ?dateOfPublication WHERE { ?book dc:date ?dateOfPublication. ?book dc:title ?bookTitle }
7
Exercise 3 Given that an RDF model represents information about books and the model is created using standard vocabularies. (i) Write a SPARQL query that returns the authors and publishers of the books for which publisher information is available. (ii) Write a SPARQL query that returns the authors and publishers of the books for which publisher might or might not be (or optionally) available.
8
Solution 3 (i) PREFIX dc: < SELECT ?bookTitle ?author ?publishingHouse WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. ?book dc:publisher ?publishingHouse }
9
Solution 3 (i) PREFIX dc: < SELECT ?bookTitle ?author ?publishingHouse WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. OPTIONAL {?book dc:publisher ?publishingHouse . } }
10
Exercise 4 Given that an RDF model represents information about books and the model is created using standard vocabularies. (i) Write a SPARQL query that returns the authors of the books in descending order. (ii) Write a SPARQL query that returns the authors of the books that have titles start with “Harry Potter”. (iii) Write a SPARQL query that returns the authors of the books that have titles containing the term “deathly” or “Deathly”.
11
Solution 4 (i) PREFIX dc: < SELECT ?bookTitle ?author WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. } ORDER BY DESC (?author)
12
Solution 4 (i) PREFIX dc: < SELECT ?bookTitle ?author WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. FILTER regex(?bookTitle, “^Harry Potter") }
13
Solution 4 (i) PREFIX dc: < SELECT ?bookTitle ?author WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. FILTER regex(?bookTitle, "deathly", "i") }
14
Exercise 5 Given that an RDF model represents information about various entities including books and the model is created using standard vocabularies. Write a SPARQL query that separates information about books i.e. title and author and creates another RDF model that is a subset of the original one. Write a SPARQL query that separates information about books i.e. title, author and publisher (if any) and creates another RDF model that is a subset of the original one.
15
Solution 5 (i) PREFIX dc: < CONSTRUCT {?book dc:creator ?author. ?book dc:title ?bookTitle} WHERE { ?book dc:creator ?author. ?book dc:title ?bookTitle. }
16
Solution 5 (ii) PREFIX dc: < CONSTRUCT {?book dc:creator ?author. ?book dc:title ?bookTitle. ?book dc:publisher ?pub } WHERE { ?book dc:creator ?author. OPTIONAL {?book dc:publisher ?pub} }
17
Exercise 6 (laboratory)
Given that an xml file contains metadata about some web resources. Publish them in an RDF model using standard vocabularies. In case of absence of some of the terms in the standard vocabularies, create a namespace and define them in the target of this namespace.
18
Exercise 7 (laboratory)
Given that an excel (.xls) file represents information about shapes of the rivers of the Trentino region. Publish them in an RDF model using standard vocabularies. In case of absence of some of the terms in the standard vocabularies, create a namespace and define them in the target of this namespace.
19
Exercise 8 (laboratory)
Given that an excel (.xls) file represents information about bicylce tracks of the Trentino region. Publish them in an RDF model using standard vocabularies. In case of absence of some of the terms in the standard vocabularies, create a namespace and define them in the target of this namespace.
20
Exercise 9 (laboratory)
Create a mash-up with data and metadata generated in the exercises 6-8 and also image data originating possibly from Flickr and finally show the result on Google Map. [P. Shvaiko, F. Farazi, V. Maltese, A. Ivanyukovich, V. Rizzi, D. Ferrari and G. Ucelli. TRENTINO GOVERNMENT LINKED OPEN GEODATA: A CASE STUDY. ISWC 2012]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.