https://www.dropbox.com/s/kc3g05y0k7t1mbw/foaf.rdf # sharing link generated by Dropbox https://dl.dropboxusercontent.com/s/kc3g05y0k7t1mbw/foaf.rdf # direct URL for SPARQLer
At the end of the lab, each group should email their first project to the teacher. It consist of:
*.ttl
file with the graph developed during the previous lab,:Hydrogen :standardState :gas .
:Hydrogen :standardState what? .
:gas
?what :standardState :gas .
:Hydrogen
:Hydrogen ?what :gas .
:standardState
SELECT ?a ?b ?c WHERE { ?a ?b ?c } LIMIT 10
rdfs:member
which is equivalent to all rdf:_1
, rdf:_2
, … relations, e.g.: BASE <http://example.org/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?who ?place WHERE { ?who <visited> [ a rdf:Bag ; rdfs:member ?place ] } LIMIT 10
selects all pairs of people and places visited by them (can be executed against https://krzysztof.kutt.pl/didactics/semweb/bob_and_mona_lisa.rdf
file)
After matching RDF graph pattern, there is also possibility to put some constraints on the rows that will be excluded or included in the results. This is achieved using FILTER construct. Let's try it now on your knowledge graphs.
So far, we have seen that the answers to questions in SPARQL can take the form of a table. In this section, we will take a look at CONSTRUCT queries which answers take the form of an RDF graph. They provide a way to introduce “rules” into RDF datasets:
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 }
SPARQL also provides two more query types:
SPARQL queries may be asked against RDF file as we did in previous sections. But there is also possibility to use special purpose web services called SPARQL Endpoints. As we already know Wikidata, we will explore the DBpedia in this section.
rdfs:label
property is useful. Maybe this will help us? Let's try!http://dbpedia.org/sparql
as SPARQL Endpoint.?country
) that probably has a relation rdfs:label
with object “Poland”@en
. This can be easily translated into SPARQL query:PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?country WHERE { ?country rdfs:label "Poland"@en . }
FILTER(ISNUMERIC(?val))
dbo
, dbr
and dbp
prefixes defined in previous section):dbr:Powiat
dbr:Voivodeships_of_Poland
SPARQL:
Sample queries in SPARQL:
Tools:
DB2RDF (RDF and Relational Databases):