Last verification: | 20180914 |
---|---|
Tools required for this lab: | – |
Video [minimum!]:
Reading:
During this lab we will use two services to execute SPARQL queries:
http://www.daml.org/2003/01/periodictable/PeriodicTable.owl
into „Target graph URI (or use FROM in the query)” field and select text output
option.http://krzysztof.kutt.pl/didactics/semweb/PeriodicTable.owl
Get Results
):PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?element ?name WHERE { ?element table:group ?group . ?group table:name "Noble gas"^^xsd:string . ?element table:name ?name . }
PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdfs: <http://w3.org/2000/01/rdf-schema#> CONSTRUCT { ?element rdfs:label ?name . } WHERE { ?element table:group ?group . ?group table:name "Noble gas"^^xsd:string . ?element table:name ?name . }
SELECT
queries do? CONSTRUCT
queries do? :Hydrogen :standardState :gas .
:Hydrogen :standardState what? .
:gas
?what :standardState :gas .
:Hydrogen
:Hydrogen ?what :gas .
:standardState
period_7
periodperiod_7
period and have OPTIONAL color (some of them does not have color!)period_7
period and have OPTIONAL color, sorted by name descendinghttp://dbpedia.org/sparql
.rdfs:label
property. Maybe this will help us? Let's try!?country
) that probably has a relation rdfs:label
with object „Polska”@pl
. This can be easily translated into SPARQL WHERE clause: ?country rdfs:label "Polska"@pl .
http://dbpedia.org/sparql
URI in the dropdown list at the top.PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?country WHERE { ?country rdfs:label "Polska"@pl . }
rdfs:label
„Polska”@pl
! -------------- | population | ============== | 38483957 | --------------
------------------------------------------------ | voivodeship | counties | ================================================ | "Masovian Voivodeship"@en | 15 | | "Greater Poland Voivodeship"@en | 12 | | "Lesser Poland Voivodeship"@en | 11 | | "Podkarpackie Voivodeship"@en | 10 | | "Pomeranian Voivodeship"@en | 9 | | "Warmian-Masurian Voivodeship"@en | 9 | | "West Pomeranian Voivodeship"@en | 9 | | "Opole Voivodeship"@en | 8 | ------------------------------------------------
or in Polish:
-------------------------------------------------- | wojewodztwo | powiaty | ================================================== | "Województwo mazowieckie"@pl | 15 | | "Województwo wielkopolskie"@pl | 12 | | "Województwo małopolskie"@pl | 11 | | "Województwo podkarpackie"@pl | 10 | | "Województwo pomorskie"@pl | 9 | | "Województwo warmińsko-mazurskie"@pl | 9 | | "Województwo zachodniopomorskie"@pl | 9 | | "Województwo opolskie"@pl | 8 | --------------------------------------------------
http://dbpedia.org/resource/Powiat
http://dbpedia.org/resource/Voivodeships_of_Poland
is_father_of
or is_child_of
or maybe both of them?is_father_of
. Now, you can execute CONSTRUCT query that creates inverse relation: PREFIX bb: <http://yourname/b-and-b#>. CONSTRUCT { ?child bb:is_child_of ?father . } WHERE { ?father bb:is_father_of ?child }
is_uncle_of
relation will be useful? No problem! PREFIX bb: <http://yourname/b-and-b#>. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> CONSTRUCT { ?uncle bb:is_uncle_of ?child . } WHERE { ?uncle bb:is_sibling_of ?parent; a bb:Man. ?child bb:is_child_of ?parent }
is_sibling_of
but instead you have is_sister_of
and is_brother_of
. Simply prepare query (or queries) that creates is_sibling_of
for you.www.dropbox.com
part of the shared link to dl.dropboxusercontent.com
SPARQL also provides two more query types: ASK and DESCRIBE.
PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> ASK { ?element table:name "aluminium"^^xsd:string . }
If you run this query against Periodic Table, answer will be yes.
MusicCD
and was published by Warner Music Group
(if you don't have such classes in your library, use analogous class that you have).DESCRIBE <http://www.daml.org/2003/01/periodictable/PeriodicTable#H>
(it should be executed against http://www.daml.org/2003/01/periodictable/PeriodicTable.owl
file)
foaf:Person
items from your model (if you don't have a foaf:Person
class in your library, use analogous class that you have).SELECT ?actor WHERE {?actor :playedIn :ReturnOfTheJedi . NOT EXISTS {?actor :diedOn ?deathdate . } }
SELECT actor_name FROM movies WHERE title = "Return of the Jedi" AND NOT EXISTS (SELECT * FROM deaths WHERE movies.actor_name = deaths.name);
If you are interested in querying the huge amount of data available in Wikipedia, there are two projects you may be interested in:
They overlap in part, but are independent of each other and have different uses. For you, a student of the Semantic Web Technologies course, it does not matter much. They are simply large knowledge bases with which you can do a lot of things.
If you want to dive into this data you can start with a Big set of SPARQL queries against Wikidata.
SPARQL:
Sample queries in SPARQL:
Tools:
Open Data Sets:
DB2RDF (RDF and Relational Databases):