An introduction to RDF querying in SPARQL
Zwifi
20.8K views
Let's FILTER some results
Cleaner explanations will be available soon.
General filtering structure
Who are the actors born before 1960?
1
2
3
4
5
6
7
8
9
10
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:birthYear ?year.
FILTER(?year < 1960)
}
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Filtering with functions
Are mail addresses usable as is?
1
2
3
4
5
6
7
8
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE {
?x foaf:name ?name ;
foaf:mbox ?mbox .
FILTER isIRI(?mbox)
}
1
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
Filtering with language
Who has a spanish name?
1
2
3
4
5
6
7
8
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE {
?x foaf:name ?name ;
foaf:mbox ?mbox .
FILTER ( lang(?name) = "ES" )
}
1
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
Filtering with datatypes
Who uses european shoe size?
1
2
3
4
5
6
7
8
9
10
11
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX eg: <http://example.org/ns#>
SELECT ?name ?shoeSize
WHERE {
?x foaf:name ?name ;
eg:shoeSize ?shoeSize .
FILTER ( datatype(?shoeSize) = xsd:integer )
}
1
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
Filtering by inclusion
What are the movies directed by Lilly Wachowski or Tom Tyker?
1
2
3
4
5
6
7
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
SELECT ?movie
WHERE {
?director yaco:directed ?movie.
FILTER(?director in (:LillyWachowski, :TomTykwer))
}
1
@prefix yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#> .
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.